Microsoft Visual C ++, compiling small sources without a project file

Well, I used Dev-C ++ for some time to learn the [C ++] language, and some things worked incorrectly, like global and local variables. Then I decided to download Microsoft Visual C ++ to see how it compares, and it was absolutely great; especially with its aesthetics. However, one thing that bothered me is that since I need to make a lot of small source files to check what I found out, I have to create a large project file each time that takes ~ 18 mb of space, I tried to just create the source the file is in C ++, but it never works, since the compilation and launch buttons are not selected without the project file, and pressing the f5 key also does not produce results. But with Dev-C ++, I could just open it, control + n and quickly write the program, compile and display it, not needed for the project file. So, is there a way to compile single source files in Microsoft Visual C ++ without requiring the project file to include it in?

+4
source share
4 answers

I usually do one project for temporary work and just reuse it. If you really have a desperate need to store training files, just create one project, add new source files and exclude all old ones from the assembly. There is no need to create a new project for each temporary or training project.

+6
source

For a simple program, you can easily compile from the command line,

Star Menu-> Visual Studio-> Visual Studio Tools-> Command Prompt

cd c:\..\your program path cl.exe test.cpp 
+17
source

You can execute the compiler from the command line. First, you will need to open a command prompt so that all the VC ++ environment variables are set. Then you simply call "cl" with the parameters you want .

If you want to stay in the IDE, you can configure the External Tool to compile it for you:

  • In Visual Studio, select Tools \ External Tools
  • Click "Add" in the dialog box.
  • Choose a suitable name, for example "Compile"
  • For "Command" select cl.exe
  • Foor "Arguments" enter $ (ItemPath)
  • Select the Use Output Window check box to send the compiler output to the output window.

Now, to use this, you must call Visual Studio with the specified environment variables. One way is to run the Visual Studio command prompt, and then enter the devenv.exe file. Then open the file you want to compile and select a new tool from the Tools menu.

+1
source

I was looking through the answers, but just thought, hmm ... What about just adding

/ * "My code ...." * /

It just comments on everything between / * ..... * /

Then remove / * ..... * / if I want to run specific code later. This way you do not need to delete your old code with Exclude From Project :)

-3
source

All Articles