读取文件 lhc.txt, 内容如下:
zhongguo 1 2 3 4 chinese
#include<iostream>
#include<sstream>#include<string>
#include<fstream>
int main()
{
std::string filename = "lhc.txt";
std::ifstream infile( filename.c_str() );
std::string str1, str2 ;
int a[4];
std::string lineStr;
std::stringstream ss;
while ( std::getline(infile,lineStr) )
{
ss << lineStr;
ss >> str1;
for(int i=0; i<4; i++ )
ss >&

这篇博客展示了如何使用C++进行文本文件的读取和写入操作。通过示例代码,解释了如何整行读取.txt文件,并将数据写入到另一个.txt文件中,包括字符串和浮点数的写入。
最低0.47元/天 解锁文章
2132

被折叠的 条评论
为什么被折叠?



