io20_8.01.c

来自「C++ Primer(第三版)的随书源代码」· C语言 代码 · 共 43 行

C
43
字号
#include <string>
#include <fstream>
#include <sstream>

/**
 ** note: no available sstream implementation
 **       available at this time -- code has not
 **       been exercised
 **
 **/

string read_file_into_string()
{
	ifstream ifile( "alice_emma" );
	ostringstream buf;
	char ch;
	while ( buf && ifile.get( ch ))
 	        buf.put( ch );
	return buf.str();
}

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

	// marks the position of each newline within 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 );
	}

	// ...
}





⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?