Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

imports <string.h> giving errors.

Status
Not open for further replies.

ironmunk

Technical User
Aug 21, 2001
51
CA
Hi ppl.. below is just some test code I found to see if string works on my system. The error I get is: error C2065: 'string' : undeclared identifier

It is includes, what could be wrong?

#include <iostream.h>
#include <string>

void main()
{
string stringA = &quot;Nutcracker&quot;,
stringB = &quot;Sleeping Beauty&quot;,
stringC = &quot;Swan Lake&quot;;
}

 
you have two choices:
1. Add using namespace std; before main()
2. change the type string to std::string

It is a namespace issue.
 
error C2871: 'std' : does not exist or is not a namespace

thats the error i get when I type in

using namespace std; //before main()
 
This code compiled for me - are you sure you got it right?

Also, you should use <iostream> not <iostream.h>


#include <iostream.h>
#include <string>


using namespace std;

void main()
{
string stringA = &quot;Nutcracker&quot;,
stringB = &quot;Sleeping Beauty&quot;,
stringC = &quot;Swan Lake&quot;;
}
 
Its funny.. your code (copy/pasted) worked.. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top