1

I am trying to run the following code:

#include <iostream(greater than sign)

using namespace std;

int main(void){

    cout << "Hello World!" << endl;

    return 0; 
}

When I run it through Output, it executes perfectly fine. But, I want to run it in Terminal so I can have input options. However, when I set "Code-runner: Run In Terminal" to true and try to run the code, I get this error message:

$ cd "c:\Users\User\Desktop\CS101\" && g++ helloworld.cpp -o helloworld && "c:\Users\User\Desktop\CS101\"helloworld

bash: cd: c:\Users\User\Desktop\CS101" && g++ helloworld.cpp -o helloworld && c:UsersUserDesktopCS101"helloworld: No such file or directory

I'm not sure what the problem is, because when I create a C file in the same folder and run it via gcc (filename).c -> ./a.exe , it also works fine. Anyone know what the problem is?

Luke B
  • 2,075
  • 2
  • 18
  • 26
Thedis
  • 11
  • 1
  • For security reasons, the search path in bash does not usually include the current directory. To run, use `./helloworld` -- note also that Windows directory separators are not valid in bash. Use `/` instead. – paddy Dec 13 '21 at 02:09
  • Now when I type /helloworld , I get this message: bash: /helloworld: No such file or directory Also, for some reason my terminal in VS is /cygdrive/c/Users/User/Desktop/CS101, yet my cmd only shows C:\Users\User. Could this be the problem? I'm trying to confirm if this is the issue, but everytime I use cd to reach CS101, close my cmd, and then run it again, my cmd only shows C:\Users\User. Thank you for your help! I really appreciate it. I've been wracking my brain on this issue all day lol. – Thedis Dec 13 '21 at 03:18
  • In bash: `cd /cygdrive/c/Users/User/Desktop/CS101; ./helloworld` ... or: `/cygdrive/c/Users/User/Desktop/CS101/helloworld`. From windows command prompt, yes, the local directory when you open `cmd` is your user directory `C:\Users\User` by default. From that location you can `cd Desktop\CS101` and run your program. – paddy Dec 13 '21 at 03:49

0 Answers0