[spoiler title=”Lesson Video”]
Direct Download of Video (For mobile / offline viewing)(right click > save target as)
[/spoiler]
[spoiler title=”Lesson Source Code”]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include
#include
#include
using namespace std;
int main(){
string str = "";
int value = 0;
bool cont = true;
while (cont){
cout << "Enter a value: ";
getline(cin, str);
stringstream ss(str);
if (ss >> value && value >5 ){
cont = false;
}
}
cout << endl;
system("PAUSE");
return 0;
}
|
[/spoiler]
Homework: None
What is StringStream?
StringStream is a library that is used to convert from strings to numeric types in C++. StringStream models it’s usage behaviors after iostream so it’s easy to learn for people that are familiar with the basics of C++. StringStream replaces older methods of doing this like atoi or itoa and gives a much safer, error-free method of handling data parsing in C++.