| View previous topic :: View next topic |
| Author |
Message |
zhanfeng123 How do I cheat?
Reputation: 0
Joined: 20 Jan 2008 Posts: 9
|
Posted: Tue Dec 30, 2008 12:27 pm Post subject: C++ String [Solved] |
|
|
| Code: | #include <iostream>
#include <string>
int main(int argc, char *argv[])
{
string word = "Hello There.";
cout<<word <<"\n";
cin.get();
return 0;
} |
Error | Code: | | c:\documents and settings\user\my documents\visual studio 2008\projects\c++string\c++string\c++string.cpp(6) : error C2065: 'string' : undeclared identifier |
The compiler does not seem to recognize the declaration of a string type. Any solution to this?
Thanks in advance.
Last edited by zhanfeng123 on Tue Dec 30, 2008 2:09 pm; edited 1 time in total |
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Dec 30, 2008 12:41 pm Post subject: |
|
|
try declaring it first, then assigning it letters
string word;
then in your function..
word = "Hello there."
_________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 30, 2008 12:52 pm Post subject: |
|
|
| string is declared in the namespace std, so use std::string or add "using namespace std".
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 30, 2008 12:55 pm Post subject: |
|
|
| Code: | | std::string word = "Hello There."; |
Edit: Evil Symbol is evil
|
|
| Back to top |
|
 |
zhanfeng123 How do I cheat?
Reputation: 0
Joined: 20 Jan 2008 Posts: 9
|
Posted: Tue Dec 30, 2008 2:09 pm Post subject: |
|
|
| Symbol wrote: | | string is declared in the namespace std, so use std::string or add "using namespace std". |
Thanks it worked. I forgot to put using namspace std nowonder my code seems to be missing something ;p
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Dec 30, 2008 3:52 pm Post subject: |
|
|
| Urhm, try using char instead of string.
|
|
| Back to top |
|
 |
Travis13 Expert Cheater
Reputation: 0
Joined: 17 Feb 2007 Posts: 199
|
Posted: Tue Dec 30, 2008 5:17 pm Post subject: |
|
|
| _void_ wrote: | | Urhm, try using char instead of string. |
LOL..........i thought u were like "uber pro" yet u didnt catch this mistake?
using namespace std; // one of the first things u learn in c++
and i didnt get to the thread fast enough so thats why i couldnt correct it
_________________
Learning C++, trying, failing, never gonna give up tho  |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Dec 30, 2008 5:34 pm Post subject: |
|
|
| Travis13 wrote: | | _void_ wrote: | | Urhm, try using char instead of string. | LOL..........i thought u were like "uber pro" yet u didnt catch this mistake? | .._void_ über pro.. :D
You may also use the default constructor instead of using = : | Code: | | std::string word("Hello there."); |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Dec 30, 2008 5:57 pm Post subject: |
|
|
| _void_ wrote: | | Urhm, try using char instead of string. |
string.c_str()
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Dec 30, 2008 7:00 pm Post subject: |
|
|
| Travis13 wrote: | | _void_ wrote: | | Urhm, try using char instead of string. |
LOL..........i thought u were like "uber pro" yet u didnt catch this mistake?
using namespace std; // one of the first things u learn in c++
and i didnt get to the thread fast enough so thats why i couldnt correct it  |
What? I already know that... I didn't say it because Reak already explained it. I meant use char* instead of string...
|
|
| Back to top |
|
 |
igoticecream Grandmaster Cheater Supreme
Reputation: 0
Joined: 23 Apr 2006 Posts: 1807 Location: 0x00400000
|
Posted: Tue Dec 30, 2008 9:36 pm Post subject: |
|
|
typedef char string[MAX_LONG_]; should solve it too (define MAX_LONG_)
_________________
+~ |
|
| Back to top |
|
 |
|