#include <stdio.h>
#include <iostream>
#include <string.h>
#include <sstream>
int main(int argc, char** argv)
{
int row, col;
const int lines = 5;// how line to read from the std::cin
std::vector< std::vector<std::string>> line_str(lines);// every line string default is lines
for (int i = 0; i < lines; i++)
{
std::string line;
std::getline(std::cin, line);
std::istringstream f(line);
//https://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g
std::vector<std::string> strings;
std::string s;
char split = ' ';// every line will be split to multi string by this character
while (getline(f, s, split)) {
line_str[i].push_back(s);
}
}
std::cout << "------------print------------" << std::endl;
for (int i = 0; i < lines; i++)
{
std::cout << i << ": ";
for (int j = 0; j < line_str[i].size(); j++)
{
cout << line_str[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << "------------print------------" << std::endl;
return 0;
}
std::cin读取行数据
最新推荐文章于 2024-05-15 19:55:15 发布