Thread: cin.getline() and getwidth help

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    20

    cin.getline() and getwidth help

    1#
    Why isn't this working? (if it cant work with string, how do I save spaces into strings?)
    cin.getline(sMovie);

    2# (need to know this tonight)
    How does getwidth work? I cant find good documentation on google.

    tnx

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    #1 cin.getline() works with c character arrays
    Code:
    char cMOvie[255];
    cin.getline(cMovie,sizeof(cMovie));
    if you use std::string object
    Code:
    std::string cMovie;
    getline(cin,cMovie);
    #2: I never heard of getwidth(), but that doesn't mean it doesn't exist

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    To use it with strings

    Code:
    getline(cin,string_name);
    cin can also be replaced with a file stream, ect.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    20
    Code:
    getline(cin, sMovie);
    Problem with that, if there is a space (example "The Matrix") I need to hit enter twice.

    So how do you format your output in a console window? (with coulombs)
    Last edited by Zeratulsdomain; 10-24-2005 at 08:30 PM.

  5. #5
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Problem with that, if there is a space (example "The Matrix") I need to hit enter twice.
    Let me guess, VC6.
    That is actually a bug in VC6. They fixed it in .net but did not fix it in any of the service packs for VC6.
    Get a different compiler

    So how do you format your output in a console window? (with coulombs)
    http://www.cplusplus.com/ref/iostream/iomanip/
    Specifically look a setw

    *edit*
    Btw though, you can fix the getline function your self:
    http://support.microsoft.com/default...;EN-US;q240015
    Last edited by Enahs; 10-24-2005 at 08:48 PM.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by Enahs
    Let me guess, VC6.
    That is actually a bug in VC6. They fixed it in .net but did not fix it in any of the service packs for VC6.
    Get a different compiler



    http://www.cplusplus.com/ref/iostream/iomanip/
    Specifically look a setw

    *edit*
    Btw though, you can fix the getline function your self:
    http://support.microsoft.com/default...;EN-US;q240015
    That is a pretty well known bug in VC6, and I fixed it on my compiler, but as I remember it, it was very hard to figure out which file contained the line of code you are supposed to change: msdn didn't have clear instructions on that.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    This is probably the solution to the problem.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That's the same link Enahs gave. Here's another one: http://www.dinkumware.com/vc_fixes.html

    The file you need to modify is <string>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL lighting problems
    By sirSolarius in forum Game Programming
    Replies: 0
    Last Post: 12-01-2003, 09:11 PM