版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bainaqianhong/article/details/55099076
问题代码
std::string cfg_file_path("./xxxx.cfg");
std::fstream fin(cfg_file_path.c_str(), std::ios_base::in);
std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
//stream_buffer_content.c_str();//this line compliled error
编译器把 stream_buffer_content
当做一个函数声明了。函数类型是 std::string (*)(std::istreambuf_iterator<char>, std::istreambuf_iterator<char>(*)());
如果你这样写的话,编译器提示无法解析的外部命令,说明stream_buffer_content确实是个函数声明
std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
stream_buffer_content(std::istreambuf_iterator<char>(fin), 0);
解决方案:
std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), (std::istreambuf_iterator<char>()));
std::istreambuf_iterator<char> end;
std::string stream_buffer_content(std::istreambuf_iterator<char>(fin), end);
std::string stream_buffer_content;
stream_buffer_content.assign(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
参考
编译器警告(等级 1)C4930 错误
stackoverflow http://stackoverflow.com/questions/12041509/possible-compiler-bug-for-c4930
总结
所有的警告都是错误