Question about "storage"

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?
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. 
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?
1
2
3
string a;
cout <<" What is your name?";
getline (cin, a);
yes. I know that. but how do I save the answer to the question for later?
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
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?
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);
So I have to have different strings. Got it. Thanks.
Topic archived. No new replies allowed.