|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
string str;
fstream iofile("file.txt",ios::out);
do
{
getline(cin,str);
iofile << str << endl;
}while(str != "end");
iofile.close();
iofile.open("file.txt",ios::in);
while(!iofile.eof())
{
iofile >> str;
cout << str << endl;
}
iofile.close();
}
目前是输出两次end,怎么样能让他不输出end呢?
如果是1个end也不输出的话,只要在
cout << str << endl;
之前写入
if (str == "end")
{
break;
}
要是想让他输出一个end
那就在
cout << str << endl;
之后添加
if (str == "end")
{
break;
}
就是说没有end就改成
if (str == "end")
{
break;
}
cout << str << endl;
要1个end就是
cout << str << endl;
if (str == "end")
{
break;
}
|
上一篇: 关于windows的线程切换,如何理解调用win32,读取内存就会切换线程下一篇: 如何定义一个动态数组通过函数生成新的数组
|