1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

New to C++ looking for help!

Discussion in 'C++' started by gloomfox, Apr 13, 2006.

  1. gloomfox

    gloomfox New Member

    Joined:
    Apr 13, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey I just started picking up c++ and was trying to write some of my own stuff. One problem I have come across is with the input. when im using standard cout/cin for strings, they work fine if i dont use a space while input'n, but as soon as I do it doesn't work.

    I think I'm looking for streams but am unfamiliar with the correct code for it.
    To use streams what do i need in the header? Does iostream work?
    what are the uses I am looking for to enjoy input with spaces and other symbols for strings????

    Thx a bunch ! :D
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    You need to be using cin.getline function for string containing spaces.

    Here is the signature of of the getline function.
    istream& getline (char* s, streamsize n, char delim );

    s
    A pointer to an array of characters.​
    n
    The maximum number of characters to store, including the ternimating null character.​
    delim
    The delimiter. The operation of extracting succesive characters is stopped when delimiter is read. This parameter is optional, if not specified the function considers '\n' the delimiter. ​
    Return Value.
    The function returns *this​
     

Share This Page