c++文件输出的小问题 谢谢!

thomaslw thomaslw 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;
int main()
{

const int str_size=100;
int i=0;
vector<string> str(str_size);
string str_temp;
fstream iofile("data.txt");
if (!iofile)
cout<<"error";
else
{

while (iofile>>str_temp)
{
cout<<"successfuly read this line. "<<endl;
cout<<"this word is "<<str_temp<<endl<<endl;
str[i++]=str_temp;
}
}
cin>>i;
return 0;

}

==========================================
环境:Dev-C++ 4.9.8.0
比如data.txt里面的数据如下:"a hello world!" 运行结束后。
data.txt里面的数据就变成了:"aa hello world!" ,以后每执行一次就多一个a.
不知道什么问题,谢谢!动手太少,多多指教!
...全文
评论 13
收藏 已收藏
分享
返回顶部
thomaslw
C++ 语言 65,214 成员 250,514 内容