Search code examples
c++filevisual-studio-codedirectoryg++

Issue with running a code on VSC due to no file or directory


I am a beginner to VSC and when I try to run the c++ code I wrote in VSC I get this error it would be really grateful if I can get a reply soon as I have an assignment to do :) Picture of the error.


Solution

  • Is the name of the file you're trying to compile "Assignment 9.cpp"? If so, it appears the compiler is seeing g++ Assignment 9.cpp and then assuming that it should be able to find two files, one called "Assignment" and one called "9.cpp".

    If you run the command g++ "Assignment 9.cpp" -o "Assignment 9", it should compile into an exe called "Assignment 9.exe". Note that you will need to use quotation marks for it to work properly.

    What's your process for compiling and running your code? And are you allowed to change the name of your file? If you can change the name, I would recommend calling the file Assignment-9.cpp, Assignment_9.cpp or Assignment9.cpp, something to get rid of the space in the name.