Thread: Using cin to read a name into 1 string

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The enter key on windows generates "\r\n", on unix "\n" and on mac "\r". Have fun!
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #17
    Registered User
    Join Date
    Nov 2003
    Posts
    26

    .......

    I was just having a problem using getline myself and I found this thread in the search. Just wanted to note that

    Code:
    char name[15];
    cin.getline ( name, '\n' );
    Does not work. I think cin.getline() expects a name and a length. Not a name and a delimiter. At least in VC7 it throws an error.

    I have been trying

    Code:
    getline(cin, string, '\n');
    which compiles fine but when the program is run the user is never prompted to enter anything. =/

    ~Joshua Norton
    Regards,
    ~Joshua Norton

  3. #18
    Registered User
    Join Date
    Nov 2003
    Posts
    26

    ...

    Bah nevermind. Of course I find the answer as soon as I post the problem.

    Code:
    cin.ignore()
    seemed to correct it.

    ~Joshua Norton
    Regards,
    ~Joshua Norton

  4. #19
    Registered User
    Join Date
    Nov 2003
    Posts
    26

    ...

    Well. Corrected it in dev C++ anyways. VC7 still skips right through the getline call. =/
    Regards,
    ~Joshua Norton

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. getline(function)??
    By dac in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 12:42 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Replies: 1
    Last Post: 07-24-2002, 06:33 AM