Question about "storage"

Jul 8, 2012 at 6:42pm
I was looking at my graphing calculator and saw the "sto" button. Which stores a number value as a letter. I was wondering if there was something like this "sto" button, but not with a number value into a letter. How can I make a storage string?
Jul 8, 2012 at 6:45pm
They're called variables.

1
2
int v = 5;  // 'v' is now memory that currently has the value of 5 stored in it
v += 5;  // add 5 more to that memory.  Now 'v' has 10 stored in it. 
Jul 8, 2012 at 7:02pm
Alright. So say I have this:
cout <<" What is your name?";
getline (cin, string);

how do I assign the answer to waht is your name, to a variable?
Jul 8, 2012 at 7:21pm
1
2
3
string a;
cout <<" What is your name?";
getline (cin, a);
Jul 8, 2012 at 7:26pm
yes. I know that. but how do I save the answer to the question for later?
Jul 8, 2012 at 7:26pm
See that variable, a? That will continue to exist until it goes out of scope. You can use it until that happens. Like this:

1
2
3
4
5
6
string a;
cout <<" What is your name?";
getline (cin, a);
...
// Later
cout << "You entered: " << a;
Last edited on Jul 8, 2012 at 7:27pm
Jul 8, 2012 at 7:30pm
oohhh. But what if I have multiple questions on the same string?

string response;
cout <<" What is your name?";
getline (cin, response);
cout <<" What is your favorite color?";
getline (cin, response);

do I just have to make the questions on separate strings?
Jul 8, 2012 at 7:32pm
1
2
3
4
5
6
string responseOne;
string responseTwo;
cout <<" What is your name?";
getline (cin, responseOne);
cout <<" What is your favorite color?";
getline (cin, responseTwo);
Jul 8, 2012 at 7:34pm
So I have to have different strings. Got it. Thanks.
Topic archived. No new replies allowed.