|
-
March 2nd, 2006, 11:27 AM
#1
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.
-
March 2nd, 2006, 11:39 AM
#2
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.
-
March 2nd, 2006, 12:03 PM
#3
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?
-
March 2nd, 2006, 12:20 PM
#4
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.
-
March 2nd, 2006, 12:24 PM
#5
Re: problem with string input
what compiler do you recommend?
-
March 2nd, 2006, 12:32 PM
#6
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.
-
March 2nd, 2006, 12:41 PM
#7
Re: problem with string input
ok thanks for the tips!!! I'll try to see if i've over looked something.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|