小小的C++程序哪里错了?

来源:百度知道 编辑:UC知道 时间:2024/06/18 03:16:57
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char *c;
int i=0;
ofstream outfile("c++.txt",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
while((c[i]=getchar())!='\n')
{
outfile<<c[i];
i++;
}
outfile.close();
return 0;
}

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char c;
int i = 0;
ofstream outfile("c++.txt", ios::out);
if(!outfile)
{
cerr << "open error!" << endl;
exit(1);
}
while((c = getchar())!='\n')
{
outfile << c;
i++;
}
outfile.close();
system("PAUSE");
return 0;
}

参考一下,下面程序. #include <stdio.h>
#include <iostream>
using namespace std;

class Test
{
public:
Test(int a=0,int b=0)
{
Test::a=a;
Test::b=b;
}
int a;
int b;
};
int main()
{
Test t(100,50);