How to compile c++ file in visual studio?

前端 未结 2 1694
北海茫月
北海茫月 2021-01-05 05:12

I am new to Visual Studio and I don\'t know how to compile a .cpp file. I made just a single .cpp file (ctr + n => Visual C++ => C++ file) and I tried to compile it. But in

相关标签:
2条回答
  • 2021-01-05 05:26

    You should, just as you did for C#, create a C++ project and add your source file to that. Then there will be all the build options you ever dreamed of.

    0 讨论(0)
  • 2021-01-05 05:27

    The problem is, Visual Studio don't really know, what to do with your .cpp file. Is it a program? Try the following:

    • File | New project
    • Visual C++ | Win32 | Win32 Project
    • Select a name and location for the project
    • Next
    • Choose Console application
    • Choose Empty project
    • Deselect Precompiled header
    • (optionally) Deselect SDL checks
    • Finish
    • Right-click on Source files and choose Add | New Item...
    • Choose C++ File
    • Choose name for this file
    • Write the following inside:

      #include <stdio.h>
      
      int main(int argc, char * argv[])
      {
          printf("Hello, world!\n");
          return 0;
      }
      
    • Press F5

    0 讨论(0)
提交回复
热议问题