Page History
...
Code Block |
---|
std::string s("121 151 225 456"); std::stringstream ss(s); T val; do { ss >> val; cout << val << endl; } while( ss.good() ); |
Input from file value by value
Code Block |
---|
#include <fstream> // for ifstream
std::ifstream f("file.txt");
if(not f.good()) ...
std::string val;
while (f>>val) {
std::cout << "val: " << val << '\n';
}
f.close(); |
Input from file line by line
Code Block |
---|
#include <fstream> // for ifstream
std::ifstream f("file.txt");
std::string line;
while (std::getline(f, line)) {
std::cout << "line: " << line << '\n';
}
f.close(); |
Print long space or repeated character
...
Overview
Content Tools