get the input but still the input should remain

Discussion in 'C++' started by Prakhar, Jul 19, 2007.

  1. Prakhar

    Prakhar Guest

    Hello,
    I know the subject line gives a little idea about the problem.

    Well, I want to get the input ,and after taking the input, I AGAIN
    want to get the same input.

    For Eg.,

    Suppose input is 23:
    ../a.out 23

    Now, I want to get 23, then store it in a variable and then again want
    to get the same input, i.e., 23.

    string strInput;
    cin>> strInput;

    int intInput;
    cin>> intInput;

    Both of them should be 23, ie, I should be able to get the input even
    if I have already taken this input.

    Thanks.-Prakhar
     
    Prakhar, Jul 19, 2007
    #1
    1. Advertising

  2. On 2007-07-19 13:56, Prakhar wrote:
    > Hello,
    > I know the subject line gives a little idea about the problem.
    >
    > Well, I want to get the input ,and after taking the input, I AGAIN
    > want to get the same input.
    >
    > For Eg.,
    >
    > Suppose input is 23:
    > ./a.out 23
    >
    > Now, I want to get 23, then store it in a variable and then again want
    > to get the same input, i.e., 23.
    >
    > string strInput;
    > cin>> strInput;
    >
    > int intInput;
    > cin>> intInput;
    >
    > Both of them should be 23, ie, I should be able to get the input even
    > if I have already taken this input.


    Use a stringstream:

    std::string strInput;
    std::cin >> strInput;

    std::stringstream ss;
    ss << strInput;

    int intInput;
    ss >> intInput;

    --
    Erik Wikström
     
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 19, 2007
    #2
    1. Advertising

  3. Prakhar wrote:
    > Hello,
    > I know the subject line gives a little idea about the problem.
    >
    > Well, I want to get the input ,and after taking the input, I AGAIN
    > want to get the same input.
    >
    > For Eg.,
    >
    > Suppose input is 23:
    > ./a.out 23
    >
    > Now, I want to get 23, then store it in a variable and then again want
    > to get the same input, i.e., 23.
    >
    > string strInput;
    > cin>> strInput;
    >
    > int intInput;
    > cin>> intInput;
    >
    > Both of them should be 23, ie, I should be able to get the input even
    > if I have already taken this input.


    That's not how things are done in C++, usually. What you [usually]
    should do is store your input, like you propose, in a string, and when
    you figure out what to convert it to, use, for example, istringstream
    to "read it again" from that string.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 19, 2007
    #3
  4. Prakhar

    Default User Guest

    Prakhar wrote:

    > Hello,
    > I know the subject line gives a little idea about the problem.
    >
    > Well, I want to get the input ,and after taking the input, I AGAIN
    > want to get the same input.
    >
    > For Eg.,
    >
    > Suppose input is 23:
    > ./a.out 23
    >
    > Now, I want to get 23, then store it in a variable and then again want
    > to get the same input, i.e., 23.
    >
    > string strInput;
    > cin>> strInput;
    >
    > int intInput;
    > cin>> intInput;
    >
    > Both of them should be 23, ie, I should be able to get the input even
    > if I have already taken this input.


    What do you mean by "input"? What you show is a command-line value. Is
    that what you are talking about? Or a value entered after the program
    starts running?




    Brian
     
    Default User, Jul 19, 2007
    #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. Chen Sun via .NET 247

    How to remain checkBox status when datagrid page changed?

    Chen Sun via .NET 247, Jul 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    522
    Joe Fallon
    Jul 3, 2004
  2. Replies:
    2
    Views:
    2,661
  3. dee
    Replies:
    7
    Views:
    512
  4. Norman Swartz
    Replies:
    25
    Views:
    1,227
    Stan McCann
    Apr 3, 2006
  5. Shin guey Wong
    Replies:
    5
    Views:
    205
    Giles Bowkett
    Dec 17, 2007
Loading...

Share This Page