我正在尝试使用向量和fstream来读取和存储C文件中的行。我使用的是Microsoft visual studio 2005。问题是,当我编译程序时,它告诉我如果我使用.h,它无法找到在include中指定的文件。如果我不使用.h,那么它将在主体中显示错误,我将向量和ifstream定义为未声明的标识符。
谢谢。
发布于 2011-03-23 13:35:55
您不能在C中使用C++类vector或fstream,C编译器无法编译它们。因此,您要么必须将文件更改为.cpp (并将其编译为C++),要么使用C语言及其文件处理方法(fopen, fprint...)和数组而不是向量。
包括
#include <stdio.h>而不是<iostream>
发布于 2011-03-23 13:36:20
如果我使用.h,则包含
。如果我不使用.h ..
我猜你包括了-
#include <vector.h>
#include <ifstream.h>.h已弃用,不应用于C++标头。所以,改成-
#include <vector>
#include <ifstream>它们都是在标准命名空间中定义的。因此,您应该导入using using指令。
using namespace std; // Probably missing this and is the cause for the errors
// vector and ifstream as undeclared identifiers.https://stackoverflow.com/questions/5401192
复制相似问题