有关 c++ 的问题

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

using namespace std;

string read_file_into_string()
{
ifstream ifile( "test1.txt" );
if( !ifile )
cout << "error\n";
ostringstream buf;
char ch;
while ( buf && ifile.get( ch ) )
buf.put( ch );
return buf.str();
}

int main()
{
string text = read_file_into_string();
cout << text;

vector<string::size_type> lines_of_text;
string::size_type pos = 0;

while( pos != string::npos )
{
pos = text.find( '\n', pos );
lines_of_text.push_back( pos );
} //调试时这里变成了死循环,跳不出来;高手指点

ostream_iterator<string::size_type> out( cout , " " );
copy( lines_of_text.begin(), lines_of_text.end(), out );

cin.get();
}


...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
lewis_c402
C++ 语言 65,214 成员 250,514 内容