#im making my first c++ program and have an error
59 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
i am also having the error:
cannot open source file "iostream". Please run the 'Select IntelliSense Configuration...' command to locate your system headers.
Your using int to define the function, that means it is expecting a value to return out of the function. To fix this do:
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
OR
#include <iostream>
void main() {
std::cout << "Hello, world!" << std::endl;
}
Voids do not expect anything to return out of them.
Hmm, how are you running the file
the main function doesn't require an explicit return statement, but must have int for a return type. See https://en.cppreference.com/w/cpp/language/main_function
OP's error is due to a misconfiguration of vscode
if you are using windows, I would advise you use visual studio 2022 instead of vscode
also, for future reference
```cpp
int main() {}
```
int main() {}
is there ANY way for me to use vscode?i want all my programming stuff in one packet
plzzzz
sure, read the documentation and figure it out ^^
the reason we recommend VS2022 over vscode is so that you can focus on learning what you actually care about (the language), rather than to have to learn literally everything else before even getting hello world to work
i see
here's a tutorial, if you really insist on using vscode
but you still havent ansered exactly why it wont work in vscde
or why hello world wont work in it
because you didn't configure it properly
it can work in vscode, it's just a huge amount of work that can be quite overwhelming, when VS2022 is literally just a few clicks and works ootb
The code works when I run it. I’m using visual studio.
Visual studio is great because it has all the stuff to run and debug code build into it
what other things can u do in vs
U don’t need to return a value for an int function, but it is a good thing to do.
that is wrong
you need a return value for any non-void function, the only exception being main, where return 0; is added by the compiler if it is omitted from the code
U don’t need to, but it’s not a bad thing to do
there's hot reload that is pretty cool, the fact that you don't have to deal with a build system (directly) is something I've always appreciated, even if it's a limiting factor. You can also use it for some other languages
you are required to return something from a non-void function
Yes, but if ur new to C++ it dosent hurt to just say that all non-void functions require a return
Even if it’s the main function
it does hurt to say "you don't need to return from a non-void function" tho
because it is incorrect
and main isn't allowed to be void (except through non-standard compiler extensions)
Rly, I’ve always used void