开发者

fstream vector C

开发者 https://www.devze.com 2023-02-18 09:01 出处:网络
I am trying to use vector and fstream to read and store the line from a file in C. I am using Microsoft visual studio 2005. the problem is that when i compile the program, 开发者_运维技巧it says it co

I am trying to use vector and fstream to read and store the line from a file in C. I am using Microsoft visual studio 2005. the problem is that when i compile the program, 开发者_运维技巧it says it could not find the file specified in include if i use .h. if i donot use .h, then it would show error in the body where i define the vector and ifstream as undeclared identifiers.

Thank you.


You cannot use the C++ classes vector or fstream in C, the C compiler cannot compile them. So you either have to change your file to .cpp (and compile it as C++), or use the C language and its methods for file handling (fopen, fprint...) and arrays instead of vector.

Include

 #include <stdio.h>

instead <iostream>


include if i use .h. if i donot use .h ..

I guess that you are including like -

#include <vector.h>
#include <ifstream.h>

.h is deprecated and should not be used for C++ headers. So, change to -

#include <vector>
#include <ifstream>

They are both are defined in std namespace. So, you should import that using using directive.

 using namespace std; // Probably missing this and is the cause for the errors
                      // vector and ifstream as undeclared identifiers.
0

精彩评论

暂无评论...
验证码 换一张
取 消