马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 weixianlang 于 2011-9-24 17:15 编辑 #include <IOSTREAM>
#include <CSTDLIB>
#include <FSTREAM>
using namespace std;
int getnum()
{
int temp;
do
{
cout<<"1.小于0的\t"
<<"2.大于0的\t"
<<"3.等于0的\t"
<<"4.退出\n";
cin>>temp;
} while (temp<0 && temp>4);
return temp;
}
void main()
{
ifstream ifile;
ifile.open("c:\\2.txt");
if (!ifile)
{
cout<<"打开文件失败\n";
return;
}
int num,sel;
char name[30];
sel = getnum();
while (sel != 0)
{
while (!ifile.eof())
{
ifile>>name>>num;
if (sel == 1 && num<0)
{
cout<<name<<" "<<num<<endl;
}
if (sel == 2 && num>0)
{
cout<<name<<" "<<num<<endl;
}
if (sel == 3 && num == 0)
{
cout<<name<<" "<<num<<endl;
}
}
ifile.close();
ifile.open("c:\\2.txt");
sel = getnum();
}
}
第一次可以选择并输出对应的结果,可是第二次选择就不能按照程序思路走了,什么都没输出!
这是C:\2.TXT的内容
** 23
fak -10
baby 0
nice 22
come -9
lady -3
ayo 0
haha 44
|