CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2006
    Posts
    55

    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.

  2. #2
    Join Date
    Feb 2006
    Posts
    29

    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.

  3. #3
    Join Date
    Mar 2006
    Posts
    55

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.

  5. #5
    Join Date
    Mar 2006
    Posts
    55

    Re: problem with string input

    what compiler do you recommend?

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.

  7. #7
    Join Date
    Mar 2006
    Posts
    55

    Talking 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
  •  





Click Here to Expand Forum to Full Width

Featured