Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile c++ file in visual studio?

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 place where normally there's a compile button (like with c#) there is strange 'Attach' button. I don't get what's going on, but I thought, Visual C++ might be some different version of normal C++. If so is that possible to compile normal C++ file in Visual Studio?

like image 908
Fiodor Avatar asked Oct 30 '13 13:10

Fiodor


1 Answers

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

like image 145
Spook Avatar answered Sep 22 '22 01:09

Spook