是否可以使整数仅收到一个单个数字而不是两个接收输入
Is it possible to make an integer only recieve input for one single number instead of two?
我需要能够在同一行上输入一系列整数,我不能使它们成为字符,因为我需要添加整数。
#include <iostream>
#include<string>
using namespace std;
int main(){
int a; //1
int b; //2
bool sit = true;
cout << "Enter a ten digit date" <<endl;
cin>>a>>b;
cout<<a<<b<<endl;
if (sit == true){
b = b+a;
cout << b<<endl;
}
return 0;
}
所以如果我输入
12
它等到我输入两个数字,然后添加两个数字。
12
45
57
我该怎么办?谢谢
我不太了解您的问题,但这是您阅读一系列整数的方式。
int x;
cin>>x;
//keep reading x until 0 is entered
while(x!=0)
{
//do whatever you need here
cin>>x;
}
如果您知道必须阅读多少个整数,则可以使用循环。
for (int i=0;i<n;i++)
{
cin>>number;
}
相关文章:
- 如何读取单个字符并在输入两个字符序列时输出? 使用 while 循环和C++
- 为什么这个scanf()的两个不同的输入会给出两个不同的输出?
- Cin 需要两个输入
- std::具有两个输入参数的矢量构造函数
- 有没有办法将两个输入图像堆叠到卤化物发生器中的单个 4 维缓冲区中?
- 如果两个输入流相等,我如何构造主()到输出是
- C 如何进行计数循环,该循环确定两个输入数字中的哪个是最低的,并且从那里计数
- C++ 验证同一行上两个输入的第一个
- 两个输入C++来自 Bash 的 cin
- ios_base::sync_with_stdio(false) 在来自标准输入的两个输入之间不起作用
- 我们可以在两个输入之间获得时间吗?
- 两个输入函数的 T(n) 运行时
- 两个输入进入一个 while 循环
- 在两个输入c++之间花费时间
- C++分隔两个输入
- 如何从同一输入获取两个输入 (C++)
- 在C++中记住具有两个输入的函数
- C++以不同的方式读取两个输入文件
- 当我试图查看我的数组时,前两个输入不出现
- 我正在尝试比较来自两个输入文件的数据,以查看一组是否比另一组少