im totally new help!

hello guys, i need some help i start to use c++ like 1 hour ago
im lost.
i just need to create the most easy think but i have no idea how to do it

i just need to found a pixel color in my screen that goes and come back goes and comeback many time goes from red to green
when it become green i need to press the button in my keyboard E
can anyone have any advice? pls. thanks
Welcome to C++!

if you're only just starting C++, then first you should make sure that you can actually edit, compile and run C++ programs. What os/compiler are you using?

For your first(?) program, make sure this compiles and executes OK:

1
2
3
4
5
6
7
#include <iostream>

int main()
{
	std::cout << "Hi from your friendly C++ compiler!\n";
	static_assert(1 == 1);
}


which will confirm that you can compile C++17 code.
Hello JoeSidda,

Do not feel like you have to start with the 2017 standards. That will more likely just confuse you.

The minimum standard should be 2011, but more likely any IDE that you use will be using the 2024 standards and that is just fine.

Just to see that things are working your 1st program should be something like:
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "Hello World!'\n";

    return 0;  // <--- Not required, but makes a good break point. 

This will work with the 2011 standard on.


just need to found a pixel color in my screen that goes and come back goes and comeback many time goes from red to green
when it become green i need to press the button in my keyboard E


For just starting C++ an hour or so ago this is a bit much to start with for a first. Nice goat to work towards though.

A couple of things to get you started:
Prefer to use the new line (\n) over the function "endl".

The line: using namespace std; should be avoided. You are better off learning to qualify what is in the standard name space with "std::". Right now what you need to learn is small compared to what you would have to learn later.

Sorry I have to go out for a bit. I have more I will post later.

Andy
}

Your problem seems underspecified, also it typically is not something a beginner would attempt to do. It is not "the most easy". Interacting with graphics and keyboard events requires third-party libraries that you'd have to set up or know how to use.

I strongly suggest just practicing C++ basics first, otherwise you will just get overwhelmed. But if you want to trudge on ahead anyway, you could use a multimedia library like SFML, which will allow you to set up a window, draw a pixel or box on that window, and let the user handle keyboard events like pressing the E key.
https://www.sfml-dev.org/
Last edited on
Do not feel like you have to start with the 2017 standards. That will more likely just confuse you.

The minimum standard should be 2011, but more likely any IDE that you use will be using the 2024 standards and that is just fine.


The compiler and the method of compiling should most certainly support/compile C++17 code - and preferably C++20. C++17 should be the minimum - not C++11 which is now 10 years out of date (or even C++14 [bit early for the 24 {or 23} standard!])! Having a working C++17 compiler doesn't mean that these new features have to be used - just that if they can be it avoids questions about why provided/obtained code doesn't compile.
@Handy Andy,

Prefer to use the new line (\n) over the function "endl".


I would say, prefer endl over the new line.

As a beginner the small performance hit of the stream flush won't matter. It is more confusing to a beginner if, for instance, the user puts a break point at the return statement, and the stream that was written to is not flushed. The beginner will be very confused that his output does not exist.

When the beginner becomes advanced and understands why an endl may be overkill for the current project at hand, then new line is more appropriate.

BTW, I almost always use endl in my code. Never had a performance problem. Only in performance critical cases will I use the new line instead, and that is fairly rare.

Last edited on
endl is really only a performance problem with a file stream - not cout. However if learners get into the habit of using \n then they won't have to relearn not to use endl with file streams when they start learning files. Same reason to teach them to use pre-inc if possible rather than post-inc. For an int it doesn't matter, but it potentially does for classes where it's implemented. Start with good habits....
> endl is really only a performance problem with a file stream - not cout.

Unless std::ios::sync_with_stdio(false) was issued (or we are on an implementation where stdio is not line-buffered).

CoreGuidelines: "Apart from the (occasionally important) issue of performance, the choice between '\n' and endl is almost completely aesthetic."
@JoeSidda - sorry, we have digressed from your original post..
The compiler and the method of compiling should most certainly support/compile C++17 code


Agree, but for different reasons. C++17 cleans up some inconsistencies in C++11/14. So just use 17, so you don't have to deal with the work-arounds in the earlier versions.

JoeSiddaI think you need to start with seeplus' example. If you can compile and run that, you're on your way.

Also, as Granado said, you'll need to start using 3rd party libraries to access the screen and other stuff.

It gets complicated fast without a plan.
Topic archived. No new replies allowed.