c++把字符写入文件
来源:百度知道 编辑:UC知道 时间:2024/06/30 10:49:20
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class teacher{
public:
teacher()
{
name=new char[40];
}
~teacher(){delete []name;}
void input()
{char *name1;
name1=new char[40];
cin>>name1;
strcpy(name,name1);}
char get(){char *a2;a2=new char[40];strcpy(a2,name);return *a2;}
protected:
char *name;
};
void main()
{
teacher o;
o.input();
cout<<o.get();
ofstream out;
out.open("test",ios::app,0);
out<<o.get();
out.close;
}
写不进去!!
请各位大侠指点一二!!
#include<string.h>
#include<fstream.h>
class teacher{
public:
teacher()
{
name=new char[40];
}
~teacher(){delete []name;}
void input()
{char *name1;
name1=new char[40];
cin>>name1;
strcpy(name,name1);}
char get(){char *a2;a2=new char[40];strcpy(a2,name);return *a2;}
protected:
char *name;
};
void main()
{
teacher o;
o.input();
cout<<o.get();
ofstream out;
out.open("test",ios::app,0);
out<<o.get();
out.close;
}
写不进去!!
请各位大侠指点一二!!
out.open("test",ios::app,0);没有指定文件类型。
out.open("test.txt",ios::app,0);
为什么写程序都不按规范来呢?变量名一点含义都没有。
连main函数的返回值都变成void了。
为什么写程序都不按规范来呢