Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why VScode display"'iostream' file not found"in .h file?

//vector.h
#ifndef MYVECTOR_H_
#define MYVECTOR_H_

#include<iostream>
#include<vector>
using namespace std;

class vectors
{
public:
    vectors(void);
    ~vectors(void);
    vectors(int *vec,int n);
    vectors(vectors &a);
    friend vectors operator + (vectors a, vectors b);//加法
    friend vectors operator - (vectors a, vectors b);//减法
    friend vectors operator ++(vectors a);//前自增
    friend vectors operator ++(vectors a,int n);//后自增
    friend vectors operator --(vectors a);//前自减
    friend vectors operator --(vectors a,int n);//后自减
    friend vectors operator * (vectors a,vectors b);//数乘

    void Display();//显示函数

private:
    int * Vec;//向量指针
    int N;//维数
};

vectors::vectors(void)
{

}

}
#endif

I'm writing a header file by C++ in VScode, but VScode show me:

'iostream' file not found

In cpp file, it never happens. I think I should install all it need. And I never meet it before.So I don't know how to do with it.

Ok, I try to give more details.

I use vscode to write code. In last codes, I just used '.cpp' files, so I haven't get an error report. But in this time, I try to write my header file as above, vscode tell me:iostream' file not found. I can't correct it. So I ask someone for help.

like image 556
saltkun Avatar asked Oct 16 '22 08:10

saltkun


People also ask

Why is Iostream not working in Vscode?

I believe there was a problem in the configuration of the C ++ compiler. try uninstalling the extensions and the compiler and reinstalling them following the official microsoft guide: link: https://code.visualstudio.com/docs/languages/cpp.

Why there is no .h in Iostream?

Answers. iostream. h is deprecated and not a standard header. It was used in older programs before C++ was standardized, Functions like cout were defined inside iostream.

How do I run a header file in VS code?

Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Add file header. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option. The Fix all occurrences dialog will open where you can preview the changes.

Where are header files stored in VS code?

You can see an example of a header-units. json file under the installation directory for Visual Studio. For example, %ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.30. 30705\include\header-units.


1 Answers

You can try recognize the compiler. Open command palette CTRL+SHIFT+P, type C/C++: Edit Configurations (UI) and open, then choose your compiler path, for instance, C:/MinGW/bin/g++.

like image 126
shalom Avatar answered Oct 21 '22 10:10

shalom