get the input but still the input should remain

P

Prakhar

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
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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;
 
V

Victor Bazarov

Prakhar said:
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
 
D

Default User

Prakhar said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top