problem with string input
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:
Code:
#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.
Re: problem with string input
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.
Re: problem with string input
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?
Re: problem with string input
You tried this code, right?
Code:
#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.
Re: problem with string input
what compiler do you recommend?
Re: problem with string input
Any that is reasonably standards compliant. For free ones I can name G++ (from GCC, could be MinGW 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.
Re: problem with string input
ok thanks for the tips!!! I'll try to see if i've over looked something.