# string undeclared identifier?

## Recommended Posts

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
#include <stdio.h>
#include <iostream.h>
#include <string.h>

int main(int argc, char* argv[])
{
string name = "";
cin >> name;
cout << name;

return 0;
}


Its a useless program since I just want the compile to work for now. EDIT: Also, Im using VC++6

##### Share on other sites

#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>

##### Share on other sites
Thank you very much thooms. That did work although I couldve sworn i tried that before and it was saying that std was not a defined namespace. Oh well, it works now :)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982378

• 10
• 9
• 15
• 24
• 11