首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"Console::“不编译

"Console::“不编译
EN

Stack Overflow用户
提问于 2013-07-25 20:27:53
回答 2查看 1.6K关注 0票数 0

这段代码取自http://msdn.microsoft.com/en-us/library/system.console.windowwidth.aspx,我想用gcc编译器编译一下。

代码语言:javascript
复制
#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 );
}

但它显示了错误。

错误是

代码语言:javascript
复制
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) ===|

我应该向代码中添加什么?

EN

回答 2

Stack Overflow用户

发布于 2013-07-25 20:30:05

该代码不是C++,而是C++/CLI。使用Microsoft编译器来实现它。

票数 6
EN

Stack Overflow用户

发布于 2013-07-25 20:38:11

Console是一个.NET类,只能通过C++/CLI访问。

常规C++不使用.NET框架,并且不能访问其中的类。

所以你需要决定你在写哪种语言。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17858024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档