Jump to content
  • Advertisement
Sign in to follow this  
MitchellH

string undeclared identifier?

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Try this instead:


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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!