Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

VC++
VC++ Introduction
VC++ What's New
VC++ Supported Platforms
Visual C++ Settings
VC++ Breaking Changes
Visual C++ Walkthroughs
Visual C++ Editions
VC++ Project Templates
Visual C++ Guided Tour
VC++ Creating Command-Line Applications
VC++ Windows Applications
VC++ Reusable Code
VC++ Porting
VC++ Unix Users
VC++ Upgrade Wizard
VC++ Migration Primer
VC++ Managed Types
VC++ Member Declarations
VC++ Conversion Operators
VC++ Interface Member
VC++ Value Types
VC++ Boxed Value
VC++ General Language
VC++ Common Programming
VC++ Database Support
VC++ MFC Database Classes
VC++ Record
VC++ Record View
VC++ OLE DB Programming

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Creating Command-Line Applications (C++)


Previoushome Next






Creating Command-Line Applications (C++)
A D V E R T I S E M E N T
Now that we have learned about the Visual Studio IDE, we are ready to start writing programs with Visual C++. The first types of application we will learn to create are command-line applications. A command-line application does not contain a graphical user interface (GUI). Typically, command-line applications read input from the console and write output to the console instead of to a graphical window.

In this section you will learn how to create both C and C++ command-line applications. You will also learn how to create standard C and C++ programs that do not use Microsoft extensions. This is useful if you want to use Visual C++ to create applications for use on other operating systems.




Prerequisites

These topics assume that you understand the fundamentals of the C++ language.




In This Section
  • Creating a Standard C++ Program (C++)
  • Compiling a Native C++ Program from the Command Line (C++)
  • Compiling a C++ Program that Targets the CLR in Visual Studio (C++)
  • Compiling a C Program
Creating a Standard C++ Program (C++)
With Visual C++ 2008, you can create Standard C++ programs by using the Visual Studio Development Environment. In this procedure, you create a new project, add a new file to the project, modify the file to add C++ code, and then compile and run the program using Visual Studio.

You can type your own C++ program or use one of the sample programs. The sample program that we use in this procedure is a console application. This application uses the set container in the Standard Template Library (STL), which is part of the ISO C++ 98 standard.

Visual C++ complies with these standards:

  • ISO C 95
  • ISO C++ 98
  • Ecma C++/CLI 05
    Note:
    You should use the /Za compiler option if you want to enforce ANSI C++ and ANSI C compliance checking of your program (the default option is /Ze which allows Microsoft extensions to the standard). See /Za, /Ze (Disable Language Extensions) for more information.

To create a new project and add a source file

  1. Create a new project:

    On the File menu, point to New, and then click Project….

  2. From the Visual C++ project types, click Win32, and then click Win32 Console Application.
  3. Enter a project name.

    By default, the solution that contains the project has the same name as the new project, but you can enter a different name. You can enter a different location for the project if you want.

    Click OK to create the new project.

  4. In the Win32 Application Wizard, select Empty Project and click Finish.
  5. If Solution Explorer is not visible, click Solution Explorer on the View menu.
  6. Add a new source file to the project:
    • Right-click on the Source Files folder in Solution Explorer, point to Add, and click New Item.
    • Click C++ File (.cpp) from the Code node, enter a file name, and then click Add.

    The .cpp file appears in the Source Files folder in Solution Explorer and a tabbed window appears where you type in the code.

  7. Click in the newly created tab in Visual Studio and type a valid C++ program that uses the Standard C++ Library, or copy and paste one of the sample programs.

    For example, you can use the set::find (STL Samples) sample program in the Standard Template Library Samples topics in the help.

    If you use the sample program for this procedure, notice the using namespace std; directive. This directive allows the program to use cout and endl without requiring fully qualified names (std::cout and std::endl).

  8. On the Build menu, click Build Solution.

    The Output window displays information about the compilation progress, such as the location of the build log and a message that indicates the build status.

  9. On the Debug menu, click Start without Debugging.

    If you used the sample program, a command window is displayed that shows whether certain integers are found in the set.

Compiling a Native C++ Program from the Command Line (C++)
Visual C++ includes a C++ compiler that you can use to create everything from simple Visual C++ programs to Windows Forms applications and components.

In this procedure, you create simple Visual C++ programs by using a text editor and compile them on the command line.

You can also compile Visual C++ programs that you created with a text editor by using the Visual Studio development environment. See Compiling a C++ Program that Targets the CLR in Visual Studio (C++) for more information.

You can use your own Visual C++ programs instead of typing the simple programs shown in these procedures. You can also use any of the Visual C++ code sample programs in the help topics.

To create a Visual C++ source file and compile it on the command line

  1. Open the Visual Studio 2008 Command Prompt window.

    Click the Start button, point to All Programs, Microsoft Visual Studio 2008, Visual Studio Tools, and then click Visual Studio 2008 Command Prompt.

    Note:
    The Visual Studio 2008 Command Prompt automatically sets up the correct path of the Visual C++ compiler and any needed libraries. Use it instead of the regular Command Prompt window. For more information, see Setting the Path and Environment Variables for Command-Line Builds.
  2. At the command prompt, type notepad simple.cpp and press Enter.

    Click Yes when you are prompted to create a new file.

  3. In Notepad, type the following lines:
    Copy Code
    #include 
    
    int main()
    {
        std::cout << "This is a native C++ program." << std::endl;
        return 0;
    }
  4. On the File menu, click Save. You have created a Visual C++ source file.
  5. On the File menu, click Exit to close Notepad.
  6. At the command prompt, type cl /EHsc simple.cpp and press Enter. The /EHsc command-line option instructs the compiler to enable C++ exception handling. For more information, see /EH (Exception Handling Model).

    The cl.exe compiler generates an executable program simple.exe.

    You can see the executable program name in the lines of output information that the compiler displays.

  7. To see a list of all files in the directory named simple with any extension, type dir simple.* and press Enter.

    The .obj file is an intermediate format file that you can safely ignore.

  8. To run the simple.exe program, type simple and press Enter.

    The program displays this text and exits:

    This is a native C++ program.

  9. To close the Command Prompt window, type exit and press Enter.



Compiling a Visual C++ Program That Uses .NET Classes

This procedure shows the command line that you use to compile a Visual C++ program that uses .NET Framework classes.

You must use the /clr (Common Language Runtime Compilation) compiler option because this program uses .NET classes and requires the Visual C++ compiler to include the necessary .NET libraries. The Visual C++ compiler generates an .exe file that contains MSIL code instead of machine executable instructions.

You can follow the steps in this procedure to compile any sample Visual C++ program in the help topics.

To compile a Visual C++ .NET console application on the command line

  1. Open the Visual Studio 2008 Command Prompt window.

    Click the Start button, point to All Programs, Microsoft Visual Studio 2008, Visual Studio Tools, and click Visual Studio 2008 Command Prompt.

  2. At the command prompt, type notepad simpleclr.cpp and press Enter.

    Click Yes when you are prompted to create a new file.

  3. In Notepad, type the following lines:
    Copy Code
    int main()
    {
        System::Console::WriteLine("This is a Visual C++ program.");
    }
  4. On the File menu, click Save.

    You have created a Visual C++ source file that uses a .NET class (Console) and is located in the System namespace.

  5. On the File menu, click Exit to close Notepad.
  6. At the command prompt, type cl /clr simpleclr.cpp and press Enter. The cl.exe compiler generates an executable program simpleclr.exe.
  7. To see a list of all files in the directory named simpleclr with any extension, type dir simpleclr.* and press Enter.

    The .obj file is an intermediate format file that you can safely ignore.

    The .manifest file is an XML file that contains information about the assembly. (An assembly is the .NET unit of deployment, such as an .exe program or .dll component or library.)

  8. To run the simpleclr.exe program, type simpleclr and press Enter.

    The program displays this text and exits:

    This is a Visual C++ program.

  9. To close the Command Prompt window, type exit and press Enter.
Compiling a C++ Program that Targets the CLR in Visual Studio (C++)
You can create Visual C++ programs that use .NET classes and compile them by using the Visual Studio Development Environment.

For this procedure you can type your own Visual C++ program or use one of the sample programs. The sample program that we use in this procedure creates a text file named textfile.txt and saves it to the project directory.

To create a new project in Visual Studio and add a new source file

  1. Create a new project. On the File menu, point to New, and then click Project….
  2. From the Visual C++ project types, click CLR, and then click CLR Empty Project.
  3. Type a project name.

    By default, the solution that contains the project has the same name as the new project, but you can enter a different name. You can enter a different location for the project if you want.

    Click OK to create the new project.

  4. If Solution Explorer is not visible, click Solution Explorer on the View menu.
  5. Add a new source file to the project:
    • Right-click the Source Files folder in Solution Explorer, point to Add and click New Item….
    • Click C++ File (.cpp) and type a file name and then click Add.

    The .cpp file appears in the Source Files folder in Solution Explorer and a tabbed window appears where you type the code you want in that file.

  6. Click in the newly created tab in Visual Studio and type a valid Visual C++ program, or copy and paste one of the sample programs.

    For example, you can use the How to: Write a Text File sample program (in the File Handling and I/O node of the Programming Guide).

    If you use the sample program, notice that you use the gcnewkeyword instead ofnewwhen creating a .NET object, and thatgcnewreturns a handle (^) rather than a pointer (*):

    StreamWriter^ sw = gcnew StreamWriter(fileName);

    For more information on the new Visual C++ syntax, see Language Features for Targeting the CLR.

  7. On the Build menu, click Build Solution.

    The Output window displays information about the compilation progress, such as the location of the build log and a message that indicates the build status.

    If you make changes and run the program without doing a build, a dialog box might indicate that the project is out of date. Select the checkbox on this dialog before you click OK if you want Visual Studio to always use the current versions of files instead of prompting you each time it builds the application.

  8. On the Debug menu, click Start without Debugging.
  9. If you used the sample program, when you run the program a command window is displayed that indicates the text file has been created. Press any key to close the command window.

    The textfile.txt text file is now located in your project directory. You can open this file by using Notepad.

    Note:
    Choosing the empty CLR project template automatically set the /clr compiler option. To verify this, right-click the project in Solution Explorer and clicking Properties, and then check the Common Language Runtime support option in the General node of Configuration Properties.

Compiling a C Program
Visual C++ 2008 includes a C compiler that you can use to create everything from simple Visual C programs to Windows API applications.

In this procedure, you create a simple Visual C program by using a text editor and compile it on the command line.

You can use your own Visual C programs instead of typing the simple programs shown in these procedures. You can also use any Visual C code sample programs that are included in the help topics.

By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of extension, use the /Tc compiler option.

To create a Visual C source file and compile it on the command line

  1. Open the Visual Studio 2008 Command Prompt window.

    Click the Start button, point to All Programs, Microsoft Visual Studio 2008, Visual Studio Tools, and then click Visual Studio 2008 Command Prompt.

    Note:
    The Visual Studio 2008 Command Prompt automatically sets up the correct path of the Visual C compiler and any needed libraries. Use it instead of the regular Command Prompt window. For more information, see Setting the Path and Environment Variables for Command-Line Builds.
  2. At the command prompt, type notepad simple.c and press Enter.

    Click Yes when you are prompted to create a new file.

  3. In Notepad, type the following lines:
    Copy Code
    #include 
    
    int main()
    {
        printf("This is a native C program.\n");
        return 0;
    }
  4. From the File menu, select Save. You have created a Visual C source file.
  5. From the File menu, select Exit to close Notepad.
  6. At the command prompt, type cl simple.c and press Enter.

    The cl.exe compiler generates an executable program simple.exe.

    You can see the executable program name in the lines of output information the compiler displays:

    Copy Code
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    simple.c
    Microsoft (R) Incremental Linker Version 9.00
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:simple.exe
    simple.obj
  7. To see a list of all files in the directory named simple with any extension, type dir simple.* and press Enter.

    The .obj file is an intermediate format file that you can safely ignore.

  8. To run the simple.exe program, type simple and press Enter.

    The program displays this text and exits:

    This is a native C program.

  9. To close the Command Prompt window, type exit and press Enter.


Be the first one to comment on this page.




  VC++ eBooks

No eBooks on VC++ could be found as of now.

 
 VC++ FAQs
More Links » »
 
 VC++ Interview Questions
More Links » »
 
 VC++ Articles
More Links » »
 
 VC++ News
More Links » »
 
 VC++ Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: bsd programming language, bsd language programming tutorial pdf, history of bsd programming, basic bsd programming, bsd band satellite programming, syntax use in bsd programming, bsd programming software download, turbo bsd programming, bsd programming code, learn bsd programming

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.