I've been trying to understand how stringstream works and when I search on the site here the stringstream page is way too much info for me to understand all at once.
this is the example I from the tutorial I was looking at.
This line in particular is what I'm trying to understand more
stringstream(mystr) >> yours.year;
This didn't seem to work at all
yours.year = mystr
I thought the yours.year could be treated like a normal variable.
Do you have to interact with a struct's variables using that stringstream() format and what is the purpose of using getline() instead of cin?
Thinking about this a little, yours.year would be a data type movies_t and mystr is data type string.
So stringstream is how you can write data of one type to a different type?
The difference between cin >> myString; and getline(cin, myString); is that the first will only input one word (up until the first whitespace character), while the second will go all the way until a newline character, so you can enter more than one word with the second version.
One thing stringstreams are useful for is when you want to convert numbers to strings or vice-versa.
You can think of stringstreams as kind of like cout and cin, except that they work with strings instead of the standard output/input.
So for instance, this code converts an int to a string:
1 2 3 4 5
int myInt = 5;
ostringstream convert;
convert << myInt; // Kind of like 'cout << myInt;', except 'myInt' goes to
// an internal string buffer instead of the screen
string result = convert.str(); // 'result' now contains "5"
while this converts a string back to an int:
1 2 3 4 5 6
string myString = "123";
istringstream convert(myString);
int result;
convert >> result; // Kind of like 'cin >> result;', except the input is
// coming from an internal string buffer, not the user
// 'result' is now equal to 123