#include <stdio.h>
#include <iostream.h>
#include <string.h>
int main(int argc, char* argv[])
{
string name = "";
cin >> name;
cout << name;
return 0;
}
string undeclared identifier?
Im trying to use the C++ string object but when I compile, its yelling at me that its undeclared. I include string.h and looked through string.h and its not there
Its a useless program since I just want the compile to work for now.
EDIT: Also, Im using VC++6
Try this instead:
string.h and iostream.h are deprecated headers, standard C++ headers should be included without the ".h" extension. The symbols in the standard headers are placed in the "std" namespace, which is why I have added a "using namespace std;" to your original program.
I have removed "stdio.h" from your code since you never used it, if you, however, want to use something found in there (or in some of the other ANSI-C headers) you just strip the h extension and prepend a "c", so to include "stdio.h" you would do:
For more info you could check http://www.cplusplus.com/doc/ansi/hfiles.html.
#include <iostream>#include <string>using namespace std; int main(int argc, char* argv[]){ string name = ""; cin >> name; cout << name; return 0;}
string.h and iostream.h are deprecated headers, standard C++ headers should be included without the ".h" extension. The symbols in the standard headers are placed in the "std" namespace, which is why I have added a "using namespace std;" to your original program.
I have removed "stdio.h" from your code since you never used it, if you, however, want to use something found in there (or in some of the other ANSI-C headers) you just strip the h extension and prepend a "c", so to include "stdio.h" you would do:
#include <cstdio>
For more info you could check http://www.cplusplus.com/doc/ansi/hfiles.html.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement