Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 输入未知数量的整数流,并对其进行整数运算 #包括 #包括 #包括 使用名称空间std; main() { int n; char-arr[50]; 获取(arr); //输入的整数在数组中。我重新检查了。 //现在,为了找到整数的数量,…我尝试了以下方法: //我使用的输入是545255 size=sizeof(arr)/sizeof(*arr);//这里的o/p是错误的。 长度=0; while(true) { 如果(yo[length]='\0') 打破 其他的 长度++; } cout_C++_Arrays_Gets - Fatal编程技术网

C++ 输入未知数量的整数流,并对其进行整数运算 #包括 #包括 #包括 使用名称空间std; main() { int n; char-arr[50]; 获取(arr); //输入的整数在数组中。我重新检查了。 //现在,为了找到整数的数量,…我尝试了以下方法: //我使用的输入是545255 size=sizeof(arr)/sizeof(*arr);//这里的o/p是错误的。 长度=0; while(true) { 如果(yo[length]='\0') 打破 其他的 长度++; } cout

C++ 输入未知数量的整数流,并对其进行整数运算 #包括 #包括 #包括 使用名称空间std; main() { int n; char-arr[50]; 获取(arr); //输入的整数在数组中。我重新检查了。 //现在,为了找到整数的数量,…我尝试了以下方法: //我使用的输入是545255 size=sizeof(arr)/sizeof(*arr);//这里的o/p是错误的。 长度=0; while(true) { 如果(yo[length]='\0') 打破 其他的 长度++; } cout,c++,arrays,gets,C++,Arrays,Gets,要读取整数,应使用>运算符 #include<stdio.h> #include<conio.h> #include<iostream> using namespace std; main() { int n; char arr[50]; gets(arr); //the entered integers are in the array. i rechecked. //now, to find the number of integers

要读取整数,应使用
>
运算符

#include<stdio.h>
#include<conio.h>
#include<iostream>

using namespace std;

main()
{

 int n;

 char arr[50];

 gets(arr);

//the entered integers are in the array. i rechecked.

//now, to find the number of integers,... i tried these methods:

//the input i used was 5 45 25 15 5 25


 size = sizeof(arr)/sizeof(*arr); //here o/p is wrong.

 length = 0;
 while (true)
 {
    if (yo[length] == '\0')
        break;
    else
        length++;
 }
 cout<<length; // here the o/p is wrong.

//i also tried using strlen operation, but the answear is wrong.

//how else can i get the o/p as 6 ?? 
intn;
向量v;
while(cin>>n)
v、 推回(n);
之后,向量
v
包含整数列表,您可以使用:
v.size()
查询整数数量

见:

顺便说一下,我看到您使用的是
conio.h
stdio.h
,请告诉我您使用的编译器,自从TurboC++3.0问世以来,我就没有看到这些头文件


对于现代编译器,您应该包括:

仅获取计数。输入值将被丢弃

int n;
vector<int> v;

while(cin >> n)
    v.push_back(n);

我认为OP想要对值做一些事情(因此标题是:对其进行整数运算)@fjardon这本来是对您的答案的评论,但是没有格式太难看了。在本例中也是..while循环没有结束。@fjardoni正在使用devcc,…但是在程序中,循环没有结束,当我输入输入时,循环仍在运行并查找input@Keertan如果关闭输入流(^Z在windows上,我相信,或者^D在unix上)循环将结束,您也可以只输入无法识别为整数的内容(如“退出”)。
int count = 0;
int val;
while (cin >> val)
{
    count++;
}