-3

Here is my code

#include <iostream>
using namespace std;

int main() {
    int age;
    cin >> age;
    cout << "Age is " << age << endl;
    return 0;
}

Whenever I run the program, I get errors saying that 'cout', 'endl' and 'cin'are not declared in this scope. I looked up this problem online and I made sure I had the "using namespace std;". Another post mentioned this was a bug and said that to fix this bug I would change

""C_Cpp.intelliSenseEngine": "Default" to "C_Cpp.intelliSenseEngine": "Tag Parser"."

I did this and it still doesn't work. Anyone have any ideas?

Edit: Here is the Error Code:

PS C:\School\C++\C++ VSD> cd "c:\School\C++\C++ VSD\" ; if ($?) { g++ test.cpp -o test } ; if ($?) { .\test }
test.cpp:3:2: error: invalid preprocessing directive #using
 #using namespace std;
  ^~~~~
test.cpp: In function 'int main()':
test.cpp:7:5: error: 'cin' was not declared in this scope
     cin >> age;
     ^~~
test.cpp:7:5: note: suggested alternative:
In file included from test.cpp:1:
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^~~
test.cpp:8:5: error: 'cout' was not declared in this scope
     cout << "Age is " << age << endl;
     ^~~~
test.cpp:8:5: note: suggested alternative:
In file included from test.cpp:1:
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^~~~
test.cpp:8:33: error: 'endl' was not declared in this scope
     cout << "Age is " << age << endl;
                                 ^~~~
test.cpp:8:33: note: suggested alternative:
In file included from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from test.cpp:1:
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:590:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
Uviation
  • 7
  • 1
  • 4
    First of all, this is a compiler error, meaning it has nothing to do with changing intellisense settings. Have you included iostream? Also see [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – SuperStormer Sep 01 '21 at 18:55
  • I forgot to paste in the part the top part of the code, which does have #include . – Uviation Sep 01 '21 at 19:42
  • And have you pasted the EXACT code you used as the error suggests that you have not/ The error says you have typed #using not using - the "correct" solution is not to use using namespace std; – mmmmmm Sep 01 '21 at 22:47
  • Yes, the code pasted above is the exact code I used. And, I've heard people saying that using namespace std; is bad practice. I'm gonna have to do some research into that. – Uviation Sep 02 '21 at 00:15

1 Answers1

1

You have to add #include <iostream> on the beginning of your file. then it should work properly

wizarddos
  • 147
  • 1
  • 2
  • 8
  • I forgot to paste in the part the top part of the code, which does have #include . – Uviation Sep 01 '21 at 19:42
  • @Uviation it is considered impolite to change a question in a manner that invalidates a correct answer. Normally someone would have reverted the edit by now, but I'm letting this one slide because Stack Overflow really doesn't need another "You forgot to include the header" answer. Comment and close vote would have been the right course of action. Unfortunately now you're stuck. You might be able to salvage the question by adding the exact text of the error message to the question so we can see if this is a case of misconfigured intellisense or a legitimately inscrutable compiler error. – user4581301 Sep 01 '21 at 20:10
  • Thank you for the response, I apologize for my editing of the original question. I have edited the question with the error code. – Uviation Sep 01 '21 at 20:42
  • `#using namespace std;` was not what you typed as the code in the question. The compiler is complaining about the errant `#` and because of that typo you have the other errors. – drescherjm Sep 01 '21 at 20:49
  • In my code, there is no `#` before the using `namespace std;` . I'm not sure why the compiler would be saying that there's one there when there isn't. – Uviation Sep 01 '21 at 20:59
  • Maybe you did not save test.cpp before it compiled and you compiled a previous version of that file. I highly doubt that the compiler got this wrong. ***test.cpp:3:2: error: invalid preprocessing directive #using*** Says on line 3 you have `#using namespace std;` or at least the version of test.cpp that the compiler compiled had `#using namespace std;` on line 3 when you compiled. – drescherjm Sep 01 '21 at 21:00