#VS code for c++

66 messages · Page 1 of 1 (latest)

toxic stirrup
#

I can run c programs directly and get output. But for C++ im confused how it works. theres all kinds of stuff. idk how to run it through WSL. and if i run it through the terminal in VSC , it keeps giving errors. can someone just please guide me through setting this up i just want to code please 🙏

eternal gorgeBOT
#

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.

toxic stirrup
#
#include <iostream>
using namespace std;

int main() {
    cout << "hello" << end1;
    return 0;
}

i found this code in a tutorial video on youtube for setting it up. but when i run it, its not working. it gave this :

error: 'end1' was not declared in this scope
cout << "hello" << end1;
^~~~

rocky gulch
#

I think that’s the number one instead of the letter l

#

Yep it is for sure

opaque karma
#

That's the second time in two days this has happened. Never seen this mistake before, though 🤣

toxic stirrup
#

i checked again

#

same error

opaque karma
#

But it's NOT a number 1

toxic stirrup
#

oh u meant i have to use the letter ?

opaque karma
#

Yes.

#

end line... endl

toxic stirrup
#

got it, one moment

#

Build finished with error(s).

  • The terminal process failed to launch (exit code: -1).
  • Terminal will be reused by tasks, press any key to close it.

gave this now.

one other thing, the "cout" line isnt colored for me. whereas in the YT tutorial it was colored

#

like this

#

im sorry if my doubts are trivial or stupid, im new to VS and programming

cursive bolt
#

it is possible that you do not have installed the extentions how would do this for you

#

*who

toxic stirrup
opaque karma
#

"Failed to launch" is a vscode setup thing. Follow a tutorial for setting up for c++. There's one by Microsoft

toxic stirrup
#

like i said, it runs c programming properly.

toxic stirrup
#

@opaque karma i followed all the steps. in the last bit, the same problem happened again. the cout isnt colored again

toxic stirrup
#

and it gave an error once again

cursive bolt
#

can you please copy and paste the error

toxic stirrup
# cursive bolt can you please copy and paste the error

static_initialization_and_destruction_0':
c:/mingw/lib/gcc/mingw32/6.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status

Build finished with error(s).

  • The terminal process failed to launch (exit code: -1).
  • Terminal will be reused by tasks, press any key to close it.
#
#include <iostream>
using namespace std;

int main() {
    cout << "hello" << endl;
    return 0;
}

code used ^

cursive bolt
#

it seems like that you have maybe not set the correkt include path

toxic stirrup
#

how do i do that

cursive bolt
#

have you set the path in sysemviarables

#

?

toxic stirrup
cursive bolt
#

you use windows?

toxic stirrup
#

yea

cursive bolt
#

please let my know if it works

toxic stirrup
eternal gorgeBOT
#

@toxic stirrup Has your question been resolved? If so, type !solved :)

toxic stirrup
#

could it be a compiler error?

#

given that cout wasnt colored.

#

or should i have saved it in some particular format? ( right now the file name is random.cpp )

cursive bolt
#

it seems that something cannot be found according to your error somethin is wrong in the library that you are using

#

random.cpp is totally fine

opaque karma
#

Are you running code on Windows proper or in wsl?

#

Must be normal windows, right?

#

It looks you've just not installed something correctly, or perhaps some environment variable (PATH) had not been updated. Have you rebooted since installing compilers etc?

cursive bolt
#

@opaque karma i could need your help too it seems you are a good coder

opaque karma
#

The top stack overflow thread suggests you may be using gcc to compile, instead use g++

toxic stirrup
toxic stirrup
toxic stirrup
opaque karma
#

Dunno. Might be in tasks.json.

toxic stirrup
#

{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:/MinGW/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe",
""
],

@opaque karma ?

#

should i edit it?

toxic stirrup
opaque karma
#

Yeah. Google for how to reselect a different task. Idk vscode, but there will be sunbathing to type in the command pallette

#

You want a g++ option, not gcc

#

Not sure the command, but you need to reselect this

#

I mean, from that drop down... Ignore the green box

toxic stirrup
#

also, my code is running normally and works in the regular output, i just checked it. the terminal thing is the one having problems