Error E0020, error code description not found on google!

Why when i literally copy paste some code, there is always so many errors??? I checked semantics and everything is correct. I will link my source code and source i got it from... Btw c++ is backwards compatible right? Or it would compile using older ISO standard no? So i don't think that's it. And i am using VS community 19, so not having newest standard is not problem either.

Following is source code in my program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{

    char key;
    int asciiValue;

    cout << "press a key to check its ascii value\nPress ESC to exit\n" << endl;

 While(1)
    {
        key = getch();
        asciiValue = key;

        if (asciiValue == 27)
            break;
        cout << ""
    }
    return 0;
}


This is source when i got source code from: https://www.youtube.com/watch?v=6-vlLvBnIR0

I tried to google: c++ error code E0020, with description from VS: identifier "while" is undefined. And google literally didn't find any result. So whole search would be like: c++ error code E0020 "identifier "while" is undefined"
And nothing was found... Wait what??? How does something basic like that not even finds?
while, lower case, not While with an upper case w.

Too many youtube coding videos are garbage.
While I agree, the capital W is not the youtube channel's fault. It's lowercase in both the video and the pastebin link.

Compiler error message give line numbers to point to where the error is, so next time you run into something like this, look around the line number it tells you to spot typos.

Anywho, C++ is case-sensitive, so be aware of that.

Btw c++ is backwards compatible right?
With its previous standards? Not completely; there are some features deprecated or features that have become more strict as of C++11 and beyond. But as a beginner you shouldn't need to worry much about that.
Last edited on
This isn’t standard c++ anyway. conio.h is a windows extension.

But you clearly DIDN’T copy-paste the code, or it wouldn’t have suffered an uppercase/lowercase malfunction.
Hmm i could swear i saw big W, i can't explain it now as i look on the video. But i don't think that's it usually. Than probably it was incorrect code many times. I couldn't paste code from video. I should say, i written it myself according to the video. But i double checked it, before post.

Yeah i know about line number, which shows where is the error, it usually doesn't help me. I try to find error in a context of code, but i don't find anything in 99% of cases. I know it is case sensitive. I really don't know why i wrote large W in this case and i don't think semantics are usually the problem.

And because it is not completely backwards compatible as Ganado say i guess. Or some extension...

Anyway, i really don't know why even description doesn't find any results on google. And usually: even if i try include context with it and error code...

It is so annoying, i am trying to create simple c++ program, which detects a keypress and googling keeps finding solutions, which using extensions, or deprecated functions. Should i create new post, or ask in this for help ? I am reading rules, but i don't even know, if this forums is meant for posting questions: about how to make a program...
Last edited on
c++ is only somewhat portable and backwards compatible, even if you ignore all libraries outside the language (eg, cstdlib is ok but conio isnt). Really old code that may have depended on integers being 32 bit or 16 bit instead of 64, for example, could be unfixable to get working today -- all it takes is one line that assumes the size of a type that has since changed and it can break badly.

These issues can be addressed now, with precisely named types (eg int64_t) but back when, those did not exist and the coder just did what made sense.

this is just a gap in the language. Keypress isnt easy to do in c++ without operating system extensions, because of how the I/O part is handled at both ends (both by the c++ compiler/language and by the OS/hardware). Its doable, but its not simple at all, and many a coder has found this to be an aggravation. Just use the extension for your compiler/os, and if its portable, code it for each and put a compiler flag around it to use the right one for the target.

For windows specifically, getch is an option but visual studio lets you pull in keypress as well, which is a little more powerful and smart. Either one is the way to go. If you can't get getch working, ... there should be a way to help you through that, post new errors after you fix the while etc.

Yes, ask here for help. There should be some examples of both getch and keypress in these forums as well, if you search old posts. When asking here, post your code, what you want to do, and what is wrong with your own code if any (error messages? bug info eg I put in x, I get y, and I wanted z)
Last edited on
Adapted macOS Catalina version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
//#include <cstdio>

int main()
{
    // Set terminal to raw mode
    system("stty raw");
    
    // Loop for single character, 'q' to quit
    char input{0};
    while
        ( std::cout << "Press any key to continue ... " and
         (input = getchar()) and
         input != 'q'
         )
    {
        std::cout << " You pressed --" << input << "--\n";
    }
    
    // Reset terminal to normal "cooked" mode
    system("stty cooked");
    
    // And we're out of here
    std::cout << "\nThankyou and bye!!\n";
    
    return 0;
}
Topic archived. No new replies allowed.