下面这个程序改为VC++的语法习惯应如何修改!

来源:百度知道 编辑:UC知道 时间:2024/05/29 15:20:45
#include<stdlib.h>
#include<iomanip.h>
#include<math.h>
#include<stdio.h>
int main()
{
FILE *fp2;
int i;
fp2=fopen("wh2.xls","wb");
if(fp2==NULL)
{
printf("2.cannot open this file\n");
exit(0);
}
for(i=0;i<100;i++)
fprintf(fp2,"%d\t",i);
fclose(fp2);
getchar();
return 0;
}

嗯。这个程序不错:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ofstream ofs("wh2.xls");

if( ofs.fail() )
{
cerr<<"2.cannot open this file"<<endl;
return -1;
}
for ( int i=0;i<100;i++ )
{
ofs<<i<<"\t";
}
ofs.close();
system("pause");
return 0;
}

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ofstream ofs("wh2.xls");
if( ofs.fail() )
{
cerr<<"错误"<<endl;
return -1;
}
for ( int i=0;i<100;++i )
{
ofs<<i<<"\t";
}
ofs.close();
system("pause");

return 0;
}

使用C++的输入输出,加上
#include<iostream>
using namesp