Thread: Problems with getline()?

  1. #1
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401

    Problems with getline()?

    So, after finally figuring out how to read input with spaces, I end up with a second problem: I have to hit the enter key twice for the system to finally get the line.
    PHP Code:
    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
        
    string s;
        
    getline(cin,s);
        
    cout << s;
        return 
    0;

    That's my code. Whenever I enter something, I hit the enter key, and nothing happens. When I hit it a second time, it shows the output from the cout. Any ideas?
    Last edited by pianorain; 11-30-2002 at 11:31 PM.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Let me guess, you're using Visual Studio 6? I believe it's a bug in that. Maybe a service pack will fix? Not sure.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Yup, buggy...

    See
    Knowledge Base Article #240015 for fix.
    Smitty

    p.s. try that link a few times or goto MS & search for 240015
    the link is flaky for some reason.
    Last edited by codesmith; 11-30-2002 at 11:56 PM.

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    lots of thanks, guys. This was driving me crazy.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 01-02-2009, 07:24 AM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. cin and getline() problems....
    By AdampqmabA in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2008, 05:55 PM
  4. Problems with getline
    By MarlonDean in forum C++ Programming
    Replies: 5
    Last Post: 07-01-2008, 05:04 AM
  5. getline, while, string problems
    By Makachu in forum C++ Programming
    Replies: 7
    Last Post: 09-23-2007, 04:17 PM