64,631
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
void write(const string& s){
cout << s << '\n';
}
int main(){
vector<string> lst;
string s = "knife";
lst.push_back(s);
s = "fork";
lst.push_back(s);
s = "spoon";
lst.push_back(s);
for_each(lst.begin(), lst.end(), write);//这里是出错的地方。
}
#include <iostream>
using namespace std;
int main()
{
write(0, 0, 0);
string s = ""; // 没错,就是标准库的string,我可没有直接包含
cout << s << endl;
return 0;
}
追踪了一下include,下面是部分包含次序,追到最后居然又回来了。。。你有兴趣的话,慢慢查吧。或者写个脚本来搜索。
iostream
ostream
ios
bits/basic_ios.h
bits/locale_facets.h
bits/ios_base.h
bits/locale_classes.h
string // 哈哈,出现了
memory
bits/stl_algobase.h
iosfwd // 我勒个去,居然又回到了io的前置声明文件
...
void write(string& s){ // 去掉const
cout << s << '\n';
}