おい。ofstreamを使用してcharをファイルに書き込む際に問題が発生しました。これがコードの外観です(動作を示すためだけです。これは実際のコードではありません)。
char buffer[5001];
char secondbuffer[5001];
char temp;
ifstream in(Filename here);
int i = 0;
while(in.get(secondbuffer) && !in.eof[])
{
i++;
}
for(int j = 0; j < i; j++)
{
secondbuffer[j] = buffer[j];
}
ofstream fout(somefile);
fout << secondbuffer;
// end of program
問題は、最初のファイルの文字を正常に読み取ることですが、2番目のファイルに書き込むと、本来のように最初のファイルからすべての文字が追加されますが、文字がなくなると、多くの文字が追加されますファイルの終わりにある「Ì」文字の。
fx:
ファイル1: abc
ファイル2: abcÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ..
プログラムがファイルに「Ì」を保存しないようにするにはどうすればよいですか?
EDIT2:
int i = 0;
lenghtofFile++;
while(fin.get(firstfileBuffer[i]) && !fin.eof())
{
i++;
lenghtofFile++;
}
firstfileBuffer[i] = '\0';
for(int j = 0; j < lenghtofFile; j++)
{
if(secondfileBuffer[j] != ' ' && secondfileBuffer[j] != '\0')
{
secondfileBuffer[j] = function(key, firstfileBuffer[j]);
}
}
secondfileBuffer[lenghtofFile]='\0';
fout << secondfileBuffer;