繁体   English   中英

程序打印奇怪的符号到输出文件C ++

[英]Program prints weird symbols to output file C++

好的,这是一个不完整的程序的一小部分。 程序读取输入文件,进行一些计算并打印到输出文件,但输出文件中有奇怪的符号。

void printRecord (char name[20], char Id[20], ostream& outfile)
{
outfile <<  name <<  Id  << endl;
}

int main()
{
ofstream outfile;
ifstream infile; 


char file_nameI[21], file_nameO[21], name[20], Id[8];

float  hworkgrade, grade1;
int deductions;

cout << "Please enter name of input file:  ";
cin >> file_nameI;
infile.open(file_nameI);
if ( !infile)
{
  cout << "Could not open input file \n";
  return 0;
}

cout << "Please enter name of output file:  ";
cin >> file_nameO;
outfile.open(file_nameO);
if ( !outfile)
{
  cout << "Could not open output file \n";
  return 0;
}

do
{
  infile >> name >> Id;
  cout<< name << Id;
  hworkgrade = CalHworkGrade(grade1, infile);
  printRecord(name, Id, outfile);
}
while(!infile.eof());

return 0;
}

这是输出文件中的内容

?Ф,ью\\Xаѓ?Ф,ью

程序不是从输入文件中提取信息。 如果我将变量设置为hello,它们不会被新信息覆盖,程序会打印hello

char file_nameI[21], file_nameO[21], name[20] = hello , Id[8]  = hello;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM