该内存不能为“written”
#include "stdafx.h"
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <cstdlib>
int main()
{
ofstream outClientFile( "clients.dat" , ios::out );
if ( !outClientFile )
{
cout << "文件不存在!" << endl;
exit( 1 );
}
int xueHao,yuWen,shuXue,yingYu,chengXu;
char *name;//运行时出入后,一击enter键就出现“该内存不能为written
并且有警告:
warning C4700: local variable 'name' used without having been initialized
这里换成"char name[16]"就没问题了
cout << "依次输入学号、姓名、语文、数学、英语、C++程序设计各项内容:"
<< endl << "Enter end-of-file to end input.\n"
<< setw( 10 ) << "学号" << setw( 10 ) << "姓名" << setw( 10 ) << "语文"
<< setw( 10 ) << "数学" << setw( 10 ) << "英语"
<< setw( 16 ) << "C++程序设计" << endl;
while ( cin >> xueHao >> name >> yuWen >> shuXue >> yingYu >> chengXu )
{
outClientFile << setw( 10 ) << xueHao << setw( 10 ) << name
<< setw( 10 ) << yuWen << setw( 10 ) << shuXue << setw( 10 ) << yingYu
<< setw( 16 ) << chengXu << endl;
}
return 0;
}
[解决办法]
name 要先分配内存才能使用
[解决办法]
如果你使用指针动态分配内存
就要在使用前分配,使用后,你不用该内存时需要释放
new / delete (推荐使用这个)
malloc / free
[解决办法]
要分配内存阿给name不然你的东西保存到name初始化时生成的随机地址去了
[解决办法]
name没空间.