Results 1 to 7 of 7

Thread: getline question

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    how come when i use getline in the following form:

    Code:
    getline(cin,szInput,'\n');
    i have to press enter twice, once for the getline function
    to stop and one to return to the next line....

    i want it so that i press it once, it ends the function and
    returns to the next line

    anyone have any ideas?
    thx in advance
    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    char input[256];
    cin.getline (input,256);
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    can't use that, i have to store the line input in a string and i get errors when i try to use one

    getline(cin,szName,'\n') is what i'm inquring about
    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4
    Lively Member
    Join Date
    Mar 2000
    Posts
    82
    i for one am confused. could you explain a little more.
    VB 6.0 Pro | VC++ 6.0

  5. #5

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    ok, i ask for a string, the user inputs it. After the user enters the string, he/she should only have to press return once, however, you have to press it twice for it to 'step' to the next part of the code. the console will go down another line after you hit return which is NOT what i want. i want hte user to input the string, they press return, and the next piece of code is followed, as oppposed to what is happening now, having to press return twice,
    Bababooey
    Tatatoothy
    Mamamonkey

  6. #6
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You are not clear. Post the declaration for szInput, what is szInput, what kind of a variable. Is it a string <string> library, char ...
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  7. #7
    Lively Member
    Join Date
    Mar 2000
    Posts
    82
    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
    	std::string input;
    	std::cout << "Enter string:";
    	std::getline(std::cin, input);
    
    	std::cout << input << std::endl;
     
    	return 0;
    }
    VB 6.0 Pro | VC++ 6.0

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