Thread: std::string getline() weirdness

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    85

    Question

    While trying to find what was causeing the bug i desided to add cin.ignore(1024, '\n'); to see if something was still in the buffer.

    Code:
    #include <string>
    #include <otherNeededheader(s)>
    using std::string;
    using std::cout;
    using std::cin or endl or what other crap you see here; //not exact ;-)
    ...
    
    string s1;
    string s2;
    string s3;
    
    cin.ignore(1024,'\n')
    cout<<"\n Please enter something: ";
    getline(cin, s1);
    cout<<"\n\n Please enter something else: ";
    getline(cin, s2);
    cout<<"\n Please enter something else: ";
    getline(cin, s3);
    
    cout<<"\nSomething else!!!\n\n";
    
    cout<< "s1: " << s1 <<endl;
    cout<< "s2: " << s2 <<endl;
    cout<< "s3: " << s3 <<endl;
    It works but It's only a temporary fix. I'll follow the code during execution to try and find where something's not being completely read or something of that nature.

    Thank you Brewbuck

    p.s.(The reason you don't see the changes from my previous post is because I copied and pasted from the first post.)
    Last edited by A10; 08-17-2007 at 11:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 07:08 PM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM