关于文件处理的问题 [英] question about file handling
本文介绍了关于文件处理的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
void main()
{
clrscr();
char ch;
ofstream sc;
sc.open("om.txt");
while(ch!='1') //here is the problem
{
ch=getche();
sc.put(ch);
}
sc.close();
getch();
}
以上在文本文件om.txt中一次输入一个字符。问题是,当我按两次时,程序没有被正确地删除,然后编程terimate
The above enters one character at a time in text file om.txt. Problem is that program is not correctly teriminated when i press two time 1 then program terimate
推荐答案
可能是因为你通过调用来结束程序的getch
。这也会在键盘继续之前从键盘上读取一个字符...
Probably because you end the program with a call to getch
. This also reads a character from the keyboard before it continues...
你检查字符'1'但你应该检查数字1.
请确保使用getche()获取正确的字符:
you check for the char '1' but you should check for the digit 1.
Be sure that you are fetching the proper char with getche():
这篇关于关于文件处理的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文