【发布时间】:2011-03-15 18:40:13
【问题描述】:
在以下代码中:
using namespace std;
//ostream& operator<< (ostream& out,const string & str)
//{
// out << str.c_str();
// return out;
//}
int _tmain(int argc, _TCHAR* argv[])
{
ofstream file("file.out");
vector<string> test(2);
test[0] = "str1";
test[1] = "str2";
ostream_iterator<string> sIt(file);
copy(test.begin(), test.end(), sIt);
file.close();
return 0;
}
重载operator << 的正确方法是什么?
copy(test.begin(), test.end(), sIt); 工作。
我错过了什么?
编辑:我只是愚蠢...忘记包含“字符串”标题
谢谢!
【问题讨论】:
-
要格式化代码,请使用 1010 按钮。
标签: c++ string file-io vector operator-overloading