< Build & Run C++ .NET 2 | Index 1 | Index 2 >


 

 

USING VISUAL STUDIO 2005

TO BUILD AND RUN C++ .NET

CONSOLE MODE APPLICATION 3

 

 

 

  1. Open the getdrive.cpp main project file from the Solution Explorer. Copy and paste the following code sample. This C++ code will search the current machine and display all the drives and if the drive is ready it will display some information about them.

// getdrive.cpp : main project file.

 

#include "stdafx.h"

 

using namespace System;

using namespace System::IO;

 

int main(array<System::String ^> ^args)

{

      // Array to store drive string

      array<DriveInfo^>^ allDrives = DriveInfo::GetDrives();

      DriveInfo^ d;

 

      // For each drive...

      for each (d in allDrives)

      {

            // Get the following info...

            Console::WriteLine("Drive: {0}", d->Name);

            Console::WriteLine("  File type:\t\t{0}", d->DriveType);

            Console::WriteLine("  Root Directory:\t{0}", d->RootDirectory);

            // More, if the drive is ready, get the following info...

            if (d->IsReady == true)

            {

                  Console::WriteLine("  Volume label:\t\t{0}", d->VolumeLabel);

                  Console::WriteLine("  File system:\t\t{0}", d->DriveFormat);

                  Console::WriteLine("  Total size of drive:            {0, 15} bytes", d->TotalSize);

                  Console::WriteLine("  Available space to current user:{0, 15} bytes", d->AvailableFreeSpace);

                  Console::WriteLine("  Total available space:          {0, 15} bytes", d->TotalFreeSpace);

                  Console::WriteLine();

                  // More tasks:

                  //    List all the directory....

                  //    List all the files...

                  //    Create directories...

                  //    Create files...

            }

      }

      return 0;

}

 

Typing the source code in the main project file

 

  1. If there is no error, builds your project else you need to rectify the error first.

 

Building C++ .NET Console Application project

 

  1. Run your program without debugging.

 

Running a CLR C++ .NET console mode application

 

  1. The following is a sample console output.

 

 

 

 

 

 

C++ .NET program output sample on listing all the drive on the machine

 

Drive: C:\

  File type:            Fixed

  Root Directory:       C:\

  Volume label:         hd0sys

  File system:          NTFS

  Total size of drive:               104855834624 bytes

  Available space to current user:    84758011904 bytes

  Total available space:              84758011904 bytes

 

Drive: D:\

  File type:            Fixed

  Root Directory:       D:\

  Volume label:         hd0ext

  File system:          NTFS

  Total size of drive:                55175143424 bytes

  Available space to current user:    45332557824 bytes

  Total available space:              45332557824 bytes

 

Drive: E:\

  File type:            CDRom

  Root Directory:       E:\

Drive: F:\

  File type:            CDRom

  Root Directory:       F:\

Drive: G:\

  File type:            Fixed

  Root Directory:       G:\

  Volume label:         hd1a

  File system:          NTFS

  Total size of drive:                10487197696 bytes

  Available space to current user:     3949473792 bytes

  Total available space:               3949473792 bytes

 

Drive: H:\

  File type:            Fixed

  Root Directory:       H:\

  Volume label:         hd1b

  File system:          NTFS

  Total size of drive:                10487197696 bytes

  Available space to current user:     8175443968 bytes

  Total available space:               8175443968 bytes

 

Drive: I:\

  File type:            Fixed

  Root Directory:       I:\

  Volume label:         hd1c

  File system:          NTFS

  Total size of drive:                10487197696 bytes

  Available space to current user:     3725508608 bytes

  Total available space:               3725508608 bytes

 

Drive: J:\

  File type:            Fixed

  Root Directory:       J:\

  Volume label:         hd1d

  File system:          NTFS

  Total size of drive:                 9639993344 bytes

  Available space to current user:     2742689792 bytes

  Total available space:               2742689792 bytes

 

Drive: K:\

  File type:            Removable

  Root Directory:       K:\

  Volume label:         AMAD

  File system:          FAT

  Total size of drive:                 1026277376 bytes

  Available space to current user:       27066368 bytes

  Total available space:                 27066368 bytes

 

Drive: L:\

  File type:            Removable

  Root Directory:       L:\

  Volume label:

  File system:          FAT

  Total size of drive:                  519528448 bytes

  Available space to current user:      127934464 bytes

  Total available space:                127934464 bytes

 

Press any key to continue . . .

 

 

  1. Well, you may want to try other C++ .NET console applications and Windows form GUIs programming by exploring C++ .NET tutorials that use Visual C++ .NET Express Edition or re-compiling the C codes using Visual Studio.

 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Part 8


 

< Build & Run C++ .NET 2 | Index 1 | Index 2 >