将整数的输入直到C / C ++中的换行符 [英] Taking input of integers until a newline in C/C++
本文介绍了将整数的输入直到C / C ++中的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请任何人可以建议我如何输入整数,直到C ++换行。
Please anyone can suggest me how to take input of integers until a newline in C++.
输入流是
10 10 10 10 10 10 10 10 10 10,后面是C ++中的换行符。
10 10 10 10 10 10 10 10 10 10, followed by a newline in C++.
推荐答案
可能重复的:如何从文件中读取整数,在C ++中逐行读取
每行处理一行:
If you want to deal in a line per line basis:
int main()
{
std::string line;
std::vector< std::vector<int> > all_integers;
while ( getline( std::cin, line ) ) {
std::istringstream is( line );
all_integers.push_back(
std::vector<int>( std::istream_iterator<int>(is),
std::istream_iterator<int>() ) );
}
}
这篇关于将整数的输入直到C / C ++中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文