cin and spaces

Discussion in 'C++' started by Samuele Armondi, Jun 23, 2003.

  1. Hi,
    I'm trying to use cin to capture some input from the console, but it always
    seems to consider a space as the end of the string. I tried to use
    cin.getline() but it only works for char arrays, and I would rather use
    strings. At the moment, I'm using getline to read the input into a char
    array and I'm then making a string out of it. Is there a more elegant way of
    doing this?
    Thanks in advance,
    S. Armondi

    --
    To contact me by email, remove _NOSPAM_ from the address.
    Samuele Armondi, Jun 23, 2003
    #1
    1. Advertising

  2. "Samuele Armondi" <> wrote...
    > I'm trying to use cin to capture some input from the console, but it

    always
    > seems to consider a space as the end of the string. I tried to use
    > cin.getline() but it only works for char arrays, and I would rather use
    > strings. At the moment, I'm using getline to read the input into a char
    > array and I'm then making a string out of it. Is there a more elegant way

    of
    > doing this?


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

    V
    Victor Bazarov, Jun 23, 2003
    #2
    1. Advertising

  3. "Victor Bazarov" <> wrote in message
    news:...
    > "Samuele Armondi" <> wrote...
    > > I'm trying to use cin to capture some input from the console, but it

    > always
    > > seems to consider a space as the end of the string. I tried to use
    > > cin.getline() but it only works for char arrays, and I would rather use
    > > strings. At the moment, I'm using getline to read the input into a char
    > > array and I'm then making a string out of it. Is there a more elegant

    way
    > of
    > > doing this?

    >
    > std::getline(std::cin, somestring);
    >
    > V
    >
    >

    Thank you!
    Samuele Armondi, Jun 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaiwanNoWhere

    cin and cin.clear() problem

    TaiwanNoWhere, Oct 13, 2003, in forum: C++
    Replies:
    8
    Views:
    4,100
    P.J. Plauger
    Oct 17, 2003
  2. Chris Mantoulidis

    std::cin.ignore() and std::cin.clear()

    Chris Mantoulidis, Jan 6, 2004, in forum: C++
    Replies:
    5
    Views:
    17,156
    Kevin Saff
    Jan 6, 2004
  3. Aleander

    cin and cin.getline()

    Aleander, Mar 6, 2005, in forum: C++
    Replies:
    5
    Views:
    8,682
    Alex Vinokur
    Mar 6, 2005
  4. johkar
    Replies:
    2
    Views:
    2,877
    Mayeul
    Dec 10, 2009
  5. Fernando
    Replies:
    4
    Views:
    1,667
    Fernando
    Nov 16, 2011
Loading...

Share This Page