| View previous topic :: View next topic |
| Author |
Message |
LuCk Guest
|
Posted: Thu Jan 29, 2004 2:20 am Post subject: String.h |
|
|
I cant seem to get any string type variables to work....I even put this
simple program together:
----------------------------------------------------------
#include <iostream.h>
#include <string.h>
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
----------------------------------------------------------
To test if the problem is the strings and it gives me the following errors:
--------------------Configuration: Test - Win32 Debug--------------------
Compiling...
Test.cpp
c:documents and settingsownermy documentsc++test.cpp(5) : error C2065:
'string' : undeclared identifier
c:documents and settingsownermy documentsc++test.cpp(5) : error C2146:
syntax error : missing ';' before identifier 'Name'
c:documents and settingsownermy documentsc++test.cpp(5) : error C2065:
'Name' : undeclared identifier
c:documents and settingsownermy documentsc++test.cpp(6) : error C2440:
'=' : cannot convert from 'char [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
Error executing cl.exe.
Test.obj - 4 error(s), 0 warning(s)
Does anyone know whats going on and if its my string.h header file...can
someone give me a link to download it please.
Thankyou.
Regards,
Carl
|
|
| Back to top |
|
 |
osmium Guest
|
Posted: Thu Jan 29, 2004 2:27 am Post subject: Re: String.h |
|
|
LuCk writes:
| Quote: | I cant seem to get any string type variables to work....I even put this
simple program together:
----------------------------------------------------------
#include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
snip |
I think you are confusing C strings and C++ (nee STL) strings. See if your
compiler will accept
#include
You will also need a using directive.
|
|
| Back to top |
|
 |
LuCk Guest
|
Posted: Thu Jan 29, 2004 2:45 am Post subject: Re: String.h |
|
|
I tried the #include <string> in place of the #include <string.h> and it
didnt work. I still get the same exact compiler errors.
Regards,
Carl
|
|
| Back to top |
|
 |
Cy Edmunds Guest
|
Posted: Thu Jan 29, 2004 3:31 am Post subject: Re: String.h |
|
|
"LuCk" <LuCk (AT) insight (DOT) rr.com> wrote
| Quote: | I tried the #include <string> in place of the #include <string.h> and it
didnt work. I still get the same exact compiler errors.
Regards,
Carl
|
Use std::string instead of string. Or, as osmium told you, put in a "using"
clause.
--
Cy
http://home.rochester.rr.com/cyhome/
|
|
| Back to top |
|
 |
SenderX Guest
|
Posted: Thu Jan 29, 2004 3:32 am Post subject: Re: String.h |
|
|
| Quote: | #include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
|
#include
#include <string>
int main()
{
std::string Name = "Carl";
std::cout << Name << std::endl;
return 0;
}
|
|
| Back to top |
|
 |
Noah Roberts Guest
|
Posted: Thu Jan 29, 2004 9:01 am Post subject: Re: String.h |
|
|
SenderX wrote:
| Quote: | #include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
#include
#include
int main()
{
std::string Name = "Carl";
std::cout << Name << std::endl;
return 0;
}
|
or
#include
#include <iostream>
using namespace std;
int main(void)
{
string Name = "Carl";
cout << Name << endl;
return 0;
}
--
"I can't help it, the Dominating Trolls made me."
|
|
| Back to top |
|
 |
Default User Guest
|
Posted: Thu Jan 29, 2004 5:04 pm Post subject: Re: String.h |
|
|
LuCk wrote:
| Quote: |
I cant seem to get any string type variables to work....I even put this
simple program together:
----------------------------------------------------------
#include
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
|
You need to get an up-to-date book on C++ programming, one that covers
standard C++, especially the new standard library features such as
std::string.
Brian Rodenborn
|
|
| Back to top |
|
 |
LuCk Guest
|
Posted: Thu Jan 29, 2004 5:57 pm Post subject: Re: String.h |
|
|
Thanx everyone for your help!
Regards,
Carl
|
|
| Back to top |
|
 |
|