How can you edit the std::cin delim char?

Discussion in 'C++' started by Alex Snast, Jun 25, 2008.

  1. Alex Snast

    Alex Snast Guest

    hello guys

    I need to modify the std::cin delim char from the default ' ' and '\n'
    characters to ',' i know that i can edit the delim in the getline
    command however i'd like to know if there's something build in with me
    having to overload the std::cin operator

    thanks, Alex Snast.
     
    Alex Snast, Jun 25, 2008
    #1
    1. Advertising

  2. Alex Snast

    Jerry Coffin Guest

    In article <91ee4eb9-768d-4db2-99b2-a9132f6646a8
    @z66g2000hsc.googlegroups.com>, says...
    > hello guys
    >
    > I need to modify the std::cin delim char from the default ' ' and '\n'
    > characters to ',' i know that i can edit the delim in the getline
    > command however i'd like to know if there's something build in with me
    > having to overload the std::cin operator


    There are a couple of possibilities. The delimiters are defined by the
    locale, so you can define a new locale with the delimiters of your
    choice.

    You can also create a filtering streambuf to transform the input into a
    format that's easier to deal with (e.g. take the commas in the original
    input and replace them with spaces so the rest of the code only sees the
    spaces that the iostream expects to use as delimiters.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Jun 25, 2008
    #2
    1. Advertising

  3. Alex Snast

    Alex Snast Guest

    Jerry Coffin כתב:
    > In article <91ee4eb9-768d-4db2-99b2-a9132f6646a8
    > @z66g2000hsc.googlegroups.com>, says...
    > > hello guys
    > >
    > > I need to modify the std::cin delim char from the default ' ' and '\n'
    > > characters to ',' i know that i can edit the delim in the getline
    > > command however i'd like to know if there's something build in with me
    > > having to overload the std::cin operator

    >
    > There are a couple of possibilities. The delimiters are defined by the
    > locale, so you can define a new locale with the delimiters of your
    > choice.
    >
    > You can also create a filtering streambuf to transform the input into a
    > format that's easier to deal with (e.g. take the commas in the original
    > input and replace them with spaces so the rest of the code only sees the
    > spaces that the iostream expects to use as delimiters.
    >
    > --
    > Later,
    > Jerry.
    >
    > The universe is a figment of its own imagination


    How do i do it. can you show me a code example please.
     
    Alex Snast, Jun 25, 2008
    #3
  4. Alex Snast

    Jerry Coffin Guest

    In article <851d9b3b-1783-4585-8368-6a14f2c1fa87
    @a70g2000hsh.googlegroups.com>, says...

    > How do i do it. can you show me a code example please.


    http://groups.google.com/group/alt.comp.lang.learn.c-
    c++/browse_frm/thread/9ee70fc9a0fffa1c/c9daefcb5147bb19#c9daefcb5147bb19

    Has one example.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Jun 25, 2008
    #4
    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,114
    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,202
    Kevin Saff
    Jan 6, 2004
  3. Francis Bell

    get(char*, num, delim) question

    Francis Bell, May 22, 2004, in forum: C++
    Replies:
    12
    Views:
    1,327
    Francis Bell
    May 24, 2004
  4. Aleander

    cin and cin.getline()

    Aleander, Mar 6, 2005, in forum: C++
    Replies:
    5
    Views:
    8,745
    Alex Vinokur
    Mar 6, 2005
  5. puzzlecracker
    Replies:
    3
    Views:
    1,792
    Mike Wahler
    May 8, 2006
Loading...

Share This Page