C++ iostream中缺少的方法
我目前正在尝试做一些简单的IO,但是我遇到了一些无法解决的方法C++ iostream中缺少的方法,c++,iostream,mingw-w64,C++,Iostream,Mingw W64,我目前正在尝试做一些简单的IO,但是我遇到了一些无法解决的方法 #include <iostream> #include <fstream> std::string filename = "\random\location\blah"; std::ifstream test; // is defined test.open(filename); //all others not resolvable bool doesntwork = test.is_open();
#include <iostream>
#include <fstream>
std::string filename = "\random\location\blah";
std::ifstream test; // is defined
test.open(filename); //all others not resolvable
bool doesntwork = test.is_open();
bool alsodoesnt = test.good();
test.close();
错误1:
#ifdef __cplusplus
extern "C++" { // the error location, not sure what to do
template <bool __test, typename __dsttype>
struct __if_array;
template <typename __dsttype>
struct __if_array <true, __dsttype> {
typedef __dsttype __type;
};
}
#endif /*__cplusplus*/
文件名是什么类型的?另外,您可以发布编译器错误吗?您使用的是
std::string
,没有包含
。另外,它应该是test.open(filename.c_str())
,反斜杠必须转义(``是单个反斜杠字符)哇哇(内部绝望),谢谢chris。那就是最初的问题了。我会将其标记为关闭,然后四处查看这些错误消息。文件名中的反斜杠需要加倍!请记住,字符串中的反斜杠告诉编译器下一个字符将被视为特殊字符(例如,换行符为“”\n“
)。要告诉编译器字符串(或字符文字)中的反斜杠应被视为文字反斜杠,您需要有两个反斜杠:'\\'
。这对您尤其不利,因为文件名中的'\r'
和'\b'
分别代表回车和退格。
#ifdef __cplusplus
extern "C++" { // the error location, not sure what to do
template <bool __test, typename __dsttype>
struct __if_array;
template <typename __dsttype>
struct __if_array <true, __dsttype> {
typedef __dsttype __type;
};
}
#endif /*__cplusplus*/
#ifdef __cplusplus
extern "C" { //not sure what they wanted here
#endif