compile and execute a cpp code file with visual studio command line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fal11
    New Member
    • Jan 2013
    • 2

    compile and execute a cpp code file with visual studio command line

    this is my C# code
    Code:
    System.IO.Directory.SetCurrentDirectory("C:/Users/fahime/Documents/Visual Studio 2010/WebSites/MyWebSite/UserFiles/ProblemAnswers/");
    Process.Start("cmd.exe", @"/k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86");// + @"/k C:\Users\fahime\Documents\Visual Studio 2010\WebSites\MyWebSite\UserFiles\ProblemAnswers cl/EHsc 4.cpp");// + folderName + " cl/EHsc " + fileName + " > result.txt""");//, @"C:\Users\fahime\Documents\Visual Studio 2010\WebSites\MyWebSite\UserFiles\ProblemAnswers" + folderName + " cl/EHsc " + fileName + " > result.txt");
    Console.WriteLine("cl/EHsc 5.cpp");
    I want to compile my cpp code file with visual studio cmd
    Last edited by acoder; Jan 23 '13, 10:18 PM. Reason: Please use [code] tags when posting code
  • swapnali143
    New Member
    • Mar 2012
    • 34

    #2
    To edit your C program:

    From the main menu select File -> New -> Project
    In the New Project window:
    Under Project types, select Win32 - Win32 Console Application
    Name your project, and specify a location for your project directory
    Click 'OK', then 'next'
    In the Application Wizard:
    Select Console application
    Select Empty project
    Deselect Precompiled header
    Once the project has been created, in the window on the left hand side you should see three folders:
    Header Files
    Resource Files
    Source Files
    Right-click on Source Files and Select Add-> New Item
    Select Code, and give the file a name
    The default here will be a file with a *.cpp extension (for a C++ file). After creating the file, save it as a *.c file.

    To compile and run:

    Press the green play button.
    By default, you will be running in debug mode and it will run your code and bring up the command window.
    To prevent the command window from closing as soon as the program finishes execution, add the following line to the end of your main function:
    getchar();
    This library function waits for any input key, and will therefore keep your console window open until a key is pressed.

    Comment

    • fal11
      New Member
      • Jan 2013
      • 2

      #3
      No,I am a software engineer
      I want to compile a cpp code file within c# code of my website
      (I am using asp.net)I want using visual studio command line and this is my code but does not work.can you help me?
      Process.Start(" cmd.exe","/c " + @"/k ""C:\Progra m Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsa ll.bat"" x86");
      Console.WriteLi ne("cl/EHsc a.cpp");

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Doesn't work the compilation fails or doesn't work the compiler fails to run?

        Comment

        Working...