c++的平均数程序问题#include "stdafx.h"#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <string>using namespace std;char*a;char **context;int main(){ while(true){cout<&
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 17:21:19
c++的平均数程序问题#include "stdafx.h"#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <string>using namespace std;char*a;char **context;int main(){ while(true){cout<&
c++的平均数程序问题
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
char*a;
char **context;
int main(){
while(true){
cout<<"请输入数据,空格隔开:";
cin.getline(a,sizeof(a));
int b=sizeof(a);
double c;
b=1;
c=atof(strtok_s(a," ",context));
while(strtok_s(nullptr," ",context)!=nullptr){
b++;
c=atof(strtok_s(nullptr," ",context))+c;
}
cout<<"平均数是:"<<c/b;
cout<<endl;
}
system("PAUSE");
return 0;
}
这个程序有什么问题,为什么通过了编译却无法正常运行?
c++的平均数程序问题#include "stdafx.h"#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <string>using namespace std;char*a;char **context;int main(){ while(true){cout<&
个人感觉你对指针的理解很不深刻.
帮你修改了一下程序,应该可以运行了,程序如下:
#include
#include
#include
#include
#include
using namespace std;
char a[1024];
char *context=NULL;
int main(){
//while(true)
{
cout