如何修复此错误? "Method 'str' could not be resolved"
How can I fix this error? "Method 'str' could not be resolved"
这个问题的含义是什么,我该如何解决?
当我尝试使用它时,它似乎不符合str()
的功能。
事实上,我想从rhs
中取出"字符串"并将其放入this->file
,所以如果您有其他想法,那也很好。
无法解析
方法 'str' 无法解析方法 'c_str'
#include <cstdio>
#include <iostream>
#include <sstream>
class MyFile {
FILE* file;
MyFile& operator=(const MyFile& rhs) const;
MyFile(const MyFile& rhs);
public:
MyFile(const char* filename) :
file(fopen(filename, "w")) {
if (file == NULL) {
throw std::exception();
}
}
~MyFile() {
fclose(file);
}
template<typename T>
MyFile& operator<<(const T& rhs) {
std::ostringstream ss;
ss << rhs;
if (std::fputs(ss.str().c_str(), this->file) == EOF) { // Method 'str' could not be resolved
throw std::exception();
}
return *this;
}
};
您确定无法解析的函数str()
吗? 相反,我认为fputs()
无法解决。原因是fputs
期望一个const char*
,但你给它一个由str()
返回的std::string
。 试试fputs(ss.str().c_str(), this->file)
.
std::ostringstream oss;
FILE *file;
std::string s = oss.str();
std::cout << s << 'n';
std::fputs(s.c_str(), file);
隐蔽的 ostringstream 到 std::string 和 than 在常量字符中转换 *
相关文章:
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 错误"Could not find Boost"(缺少:上下文标头)
- 如何摆脱导入的 make 项目中的 Eclipse 索引器"Type std::... could not be resolved"错误
- Qt5 部署"procedure entry point could not be located"
- 模板函数参数到模板函数的"candidate template ignored: could not match ..."
- 使用自定义 nodejs 插件时的"The specified module could not be found"
- Boost.Python 和导入 dll,"The specified module could not be found"
- 如何修复此错误? "Method 'str' could not be resolved"
- Visual studio 2017 could not find LMCONS.H
- 如何修复'The procedure entry point SDL_RWclose could not be located in the dynamic link library'
- Could NOT find Qt5WebKitWidgets
- "The ordinal 344 could not be located in the dynamic link library"
- OpenCL could not found Intel HD 4000
- 如何修复窗户上的 cmake find_package "Could NOT find SDL2"?
- Libavcodec "the procedure entry point for av_frame_alloc could not be located" Visual Studio 2017 C+
- 无法运行Qt C++发布版本。 'The procedure entry point could not be located'
- 如何修复 WSL 上的智能感知'A definition for the symbol could not be located'
- "Configure: Error: Could Not Find a Working Compiler, See config.log For Details"
- MinGW在代码块中构建时的ar.exe "could not create temporary file whilst writing archive: no more archived files
- Android CMake: Could NOT find OpenSSL