0

this code is taken from http://msdn.microsoft.com/en-us/library/system.console.windowwidth.aspx I want to compile it in gcc compiler.

#include<cstdio>
#include<string>
#include<windows.h>
#include<iostream>
using namespace System;
int main()
{
   int origWidth;
   int width;
   int origHeight;
   int height;
   String^ m1 = "The current window width is {0}, and the " 
   "current window height is {1}.";
   String^ m2 = "The new window width is {0}, and the new " 
   "window height is {1}.";
   String^ m4 = "  (Press any key to continue...)";

    // 
   // Step 1: Get the current window dimensions. 
   //
   origWidth = Console::WindowWidth;
   origHeight = Console::WindowHeight;
   Console::WriteLine( m1, Console::WindowWidth, Console::WindowHeight );
   Console::WriteLine( m4 );
   Console::ReadKey( true );

   // 
   // Step 2: Cut the window to 1/4 its original size. 
   //
   width = origWidth / 2;
   height = origHeight / 2;
   Console::SetWindowSize( width, height );
   Console::WriteLine( m2, Console::WindowWidth, Console::WindowHeight );
   Console::WriteLine( m4 );
   Console::ReadKey( true );

   // 
   // Step 3: Restore the window to its original size. 
   //
   Console::SetWindowSize( origWidth, origHeight );
   Console::WriteLine( m1, Console::WindowWidth, Console::WindowHeight );
}

But it shows error.

The error is

F:\Untitled2.cpp||In function 'int main()':|
F:\Untitled2.cpp|31|error: 'Console' has not been declared|
F:\Untitled2.cpp|32|error: 'Console' has not been declared|
F:\Untitled2.cpp|33|error: 'Console' has not been declared|
F:\Untitled2.cpp|34|error: 'Console' has not been declared|
F:\Untitled2.cpp|35|error: 'Console' has not been declared|
F:\Untitled2.cpp|35|error: 'name' was not declared in this scope|
F:\Untitled2.cpp|36|error: 'Console' has not been declared|
||=== Build finished: 7 errors, 0 warnings (0 minutes, 0 seconds) ===|

What should I need to add to the code?

Maruf
  • 792
  • 12
  • 36

2 Answers2

6

That code is not C++, it is C++/CLI. Use the Microsoft compiler for it.

filmor
  • 30,840
  • 6
  • 50
  • 48
  • Can't I add any header file or use some connector to my code::blocks to compile the code.......? – Maruf Jul 25 '13 at 17:35
  • 1
    No. It is a different language, not only a different library (i.e. `String^` is not C++ at all and will fail to compile). – filmor Jul 26 '13 at 07:35
3

Console is a .NET class, and is only accessible to C++/CLI.

Regular C++ does not use the .NET framework, and does not have access to the classes in it.

So you need to decide which language you're writing.

jalf
  • 243,077
  • 51
  • 345
  • 550