如果用户输入一个整数,例如 4210,我如何在 C++ 中将该整数的每一位放入 vector 中?
最佳答案
可以这样做:
std::vector<int> numbers;
int x;
std::cin >> x;
while(x>0)
{
numbers.push_back(x%10);
x/=10;
}
std::reverse(numbers.begin(), numbers.end());
关于c++ - 如何在C++中将整数的数字放入 vector 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22818749/