String.h

L

LuCk

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 settings\owner\my documents\c++\test.cpp(5) : error C2065:
'string' : undeclared identifier
c:\documents and settings\owner\my documents\c++\test.cpp(5) : error C2146:
syntax error : missing ';' before identifier 'Name'
c:\documents and settings\owner\my documents\c++\test.cpp(5) : error C2065:
'Name' : undeclared identifier
c:\documents and settings\owner\my documents\c++\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
 
O

osmium

LuCk said:
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;
}
<snip>

I think you are confusing C strings and C++ (nee STL) strings. See if your
compiler will accept

#include <string>

You will also need a using directive.
 
L

LuCk

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
 
C

Cy Edmunds

LuCk said:
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.
 
S

SenderX

#include said:
#include <string.h>

int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}


#include <iostream>
#include <string>

int main()
{
std::string Name = "Carl";

std::cout << Name << std::endl;

return 0;
}
 
N

Noah Roberts

SenderX said:
#include <iostream>
#include <string>

int main()
{
std::string Name = "Carl";

std::cout << Name << std::endl;

return 0;
}

or

#include <string>
#include <iostream>

using namespace std;

int main(void)
{
string Name = "Carl";
cout << Name << endl;

return 0;
}
 
D

Default User

LuCk said:
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;
}


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top