06-1.cpp

来自「effective stl 源代码 code」· C++ 代码 · 共 49 行

CPP
49
字号
//
// Example from ESTL Item 6
//
// Fails under MSVC/native lib, STLPort
//

#include <list>
#include <iostream>
#include <fstream>
#include "ESTLUtil.h"

int main()
{
	using namespace std;
	using namespace ESTLUtils;

	ifstream dataFile("ints.dat");


/* incorrect, but works with some compilers: 
	{
		list<int> data(istream_iterator<int>(dataFile), // warning! this doesn抰 do
					   istream_iterator<int>());		// what you think it does
		cout << "First value in the list is " << *data.begin() << endl;
	}
*/

	
/* correct, but doesn't work with some compilers:
	{
		list<int> data((istream_iterator<int>(dataFile)),	// note new parens
					   istream_iterator<int>());			// around first argument
															// to list抯 constructor
		cout << "First value in the list is " << *data.begin() << endl;
	}
*/
	

/* should always work: */
	{
		istream_iterator<int> dataBegin(dataFile);
		istream_iterator<int> dataEnd;
		list<int> data(dataBegin, dataEnd);	

		cout << "First value in the list is " << *data.begin() << endl;
	}
	return 0;
}

⌨️ 快捷键说明

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