CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Posts
    2

    newbe/cs student needs help

    hey, im writing a prog in C++ for DOS console. i want to know how to make the program ask for keyboard input, return it, then save it to a string for later use. teacher never went over it and cant find examples.
    thank you very much

    xerocontrol [gzc]


  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: newbe/cs student needs help

    to ask for a string on the console, use

    std:string sin;
    std::cin >> sin;




    or

    std::getline( std::cin, sin );



    either way will get you a string. The difference is, the first one will only give you the word up to the first whitespace character while the second will give you a whole line.

    Both will be stored in the variable sin



    The best things come to those who rate

  3. #3
    Join Date
    Sep 2001
    Location
    Victoria, BC, Canada
    Posts
    363

    Re: newbe/cs student needs help

    What, you're doing his homework for him? :P


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

Featured