Click to See Complete Forum and Search --> : problem with string input


Tsubasa
March 2nd, 2006, 10:27 AM
Hi
I've just started programming in C++ today and I'm already encounting a problem. Well when trying to create a simple program to reading a string a output it, there's a lot of errors. Here is my program:


#include <iostream.h>
#include <string.h>
using namespace std;

int main()
{
cout<<"what is your name?"<<endl;
string first;
cin >> first;
cout<<"hi, "<< first;
return 0;

}


well after compiling it says that std , first and string are undefined indentifirers. Why is it telling me that???
can anyone help me.

dapech69
March 2nd, 2006, 10:39 AM
Drop the .h off of your includes. Most of the header files with the .h extension are the old C libraries and not the new C++ libraries.

Tsubasa
March 2nd, 2006, 11:03 AM
but if I drop the .h they the compiler will say:
Fatal error cannot open input file iostream and string. So what should I do?

laserlight
March 2nd, 2006, 11:20 AM
You tried this code, right?
#include <iostream>
#include <string>
using namespace std;

int main()
{
cout<<"what is your name?"<<endl;
string first;
cin >> first;
cout<<"hi, "<< first;
return 0;
}

If the above doesnt work, then either you're doing something wrong (e.g. not using a project or some equivalent if the development environment requires one), or you should get a newer compiler.

Tsubasa
March 2nd, 2006, 11:24 AM
what compiler do you recommend?

laserlight
March 2nd, 2006, 11:32 AM
Any that is reasonably standards compliant. For free ones I can name G++ (from GCC (http://gcc.gnu.org), could be MinGW (http://www.mingw.org) port) and MSVC8 (from Microsoft Visual C++ 2005 Express).

Of course, there's still the possibility that you've just overlooked something, and fixing that is better/easier than getting a new compiler/IDE.

Tsubasa
March 2nd, 2006, 11:41 AM
ok thanks for the tips!!! I'll try to see if i've over looked something.