[英]no matching function for getline c++
我正在尝试输入一个数字,并且基于该数字,用户将不得不输入x次。
例如
3 //how many the user wants
192 231 2 3
22192 2 1 23
2831 3 23 1
我尝试这样做,但一直说getline
没有匹配功能
int* x = NULL;
int numbers;
cin >> numbers;
x = new int[numbers]
for (int i=0;i<numbers;i++)
{
std::getline(std::cin, numbers)
x[i] = numbers
}
getline的第二个参数的类型为std::string
您绝对不希望使用std::getline
因为它看起来好像不需要数字字符串,而是数字本身。
您想要的是按数字读取数字,因此请使用与读取numbers
,但不要再次按numbers
读取它。 (因为您正在循环中使用它。)
无论如何,这是您想要的近似值:
int how_many;
std::vector<int> numbers;
std::cin >> how_many;
for (int i = 0; i < how_many; i++){
int temp;
std::cin >> temp;
numbers.push_back(temp);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.