今天写了个程序用了如下代码
#include <iostream.h>
using namespace std;
然后编译时出现 error C2871: 'std' : does not exist or is not a namespace
查了一下,原来 C++有两个不同版本的头文件。引入名字空间这个概念以前编译器用的是#include <iostream.h>,
而引入名字空间的概念以后std名字空间的头文件名字变成了<iostream>。
<iostream.h>是比较老的C++的头文件的版本,而namespace是98年才被加入C++标准的,所以<iostream.h>里面是没有std这么个命名空间的,当使用 <iostream.h>时,相当于在c中调用库函数,使用的是全局命名空间,也就是早期的c++实现。头文件<iostream>则没有定义全局命名空间,使用时必须使用namespace std才能正确使用cout。
vc6.0支持这个两个版本. 不过现在都用<iostream>了
所以只需将以上语句改为:
#include <iostream>
using namespace std;
或者是 #include <iostream.h>即可。
分享到:
相关推荐
- **代码示例**:例如,在Visual C++.NET 2003中,使用`iostream.h`可能导致编译错误,如`'std': does not exist or is not a namespace`。 #### 5. 文件结构和组织 - **文件结构**:`iostream`通常包含了其他相关...
std::cout << "Source directory does not exist." << std::endl; return; } for (const auto& entry : fs::directory_iterator(sourceDir)) { if (entry.is_regular_file()) { // 只处理文件,忽略子目录 fs...
However, implementation code properly belongs in .cc files, and we do not like to have much actual code in .h files unless there is a readability or performance advantage. If an inline function ...
printf("Does NOTEXISTS.FIL exist: %s\n", file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); return 0; } int file_exists(char* filename) { return (access(filename, 0) == 0); } ``` **解析:** 1. **引入...
cout << "Solution does not exist"; return 0; } cout << "Graph is colored as follows:\n"; for (int i = 0; i ; i++) cout << "Vertex " << i << " ---> Color " [i] ; return 0; } ``` 这段代码实现...
using namespace std; #define FILENAME "stat.dat" int main() { fstream file; file.open(FILENAME, ios::in); if (!file) { cout 没有被创建" ; } else { cout 已经存在" ; } return 0; } ``` 在这段...
printf("File ACCESS.C does not exist."); } return 0; } ``` 3. 使用POSIX标准的`stat()`函数: 在Unix-like系统中,可以使用`stat()`函数获取文件的状态信息,包括文件是否存在。`stat()`函数需要一个文件...