错误“系统”是模糊的? [英] Error "system" is ambiguous?

查看:160
本文介绍了错误“系统”是模糊的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的程序,它工作正常,但系统(CLS); 系统(暂停); 语句下面有红色IntelliSense行。当我将光标移动到它们上面时,表示错误系统是不明确的。是什么原因导致的?



是我的代码:

  #include< iostream> 
#include< cmath>
using namespace std;

int main()
{
int choice = 0;
const double PI = 3.14159;
double sideSquare = 0.0;
double radius = 0.0;
double base = 0.0;
double height = 0.0;

cout<< 这个程序计算3个不同对象的面积。 << endl;
cout<< 1.)正方形< endl;
cout<< 2.)Circle< endl;
cout<< 3.)右三角形<< endl;
cout<< 4.)终止程序< endl<< endl;

cout<< 请[Enter]你选择的对象:;
cin>>选择;
system(CLS); //问题在这里...

switch(choice)
{
case 1:
cout< 请[Enter]正方形的边长:;
cin>> sideSquare;
cout<< 区域是:< pow(sideSquare,2)< endl;
break;

case 2:
cout<< 请[Enter]圆的半径:;
cin>>半径;
cout<< 区域是:< PI * pow(radius,2)<< endl;
break;

case 3:
cout<< 请[Enter]三角形的底边:;
cin>>基础;
cout<< endl<< 现在[Enter]三角形的高度:;
cin>>高度;
cout<< 区域是:< (基底*高度)/ 2 < endl;
break;

默认值:
cout<< 请下次输入有效的选择。 << endl;
return 0;
}
system(pause); // ... 和这里。
return 0;
}


解决方案

$ c> #include< cstdlib>



资料来源: http://en.cppreference.com/w/cpp/utility/program/system



另外,尽量避免 system ,这很危险。要在程序完成时暂停该程序,请在main的末尾放置一个断点} 。没有标准的方法清除屏幕。



为了将来参考,红色波形是 intellisense 错误,一个不同的前端比实际编译代码,所以红色波浪有时是错误的,特别是对于复杂的模板。在大多数情况下,包括这一个,它是正确的。


I have a simple program, and it works fine, but the system("CLS"); and system("pause"); statements have red IntelliSense lines underneath them. When I move my cursor over them it says Error "system" is ambiguous. What is causing that?

Here is my code:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  int choice = 0;
  const double PI = 3.14159;
  double sideSquare = 0.0;
  double radius = 0.0;
  double base = 0.0;
  double height = 0.0;

  cout << "This program calculates areas of 3 different objects." << endl;
  cout << "1.) Square" << endl;
  cout << "2.) Circle" << endl;
  cout << "3.) Right Triangle" << endl;
  cout << "4.) Terminate Program" << endl << endl;

  cout << "Please [Enter] your object of choice: ";
  cin >> choice;
  system("CLS"); // The problem is here...

  switch(choice)
  {
   case 1: 
    cout << "Please [Enter] the length of the side of the square: ";
    cin >> sideSquare;
    cout << "The area is: " << pow(sideSquare, 2) << endl;
    break;

   case 2: 
    cout << "Please [Enter] the radius of the circle: ";
    cin >> radius;
    cout << "The area is: " << PI * pow(radius, 2) << endl;
    break;

    case 3:
    cout << "Please [Enter] the base of the triangle: ";
    cin >> base;
    cout << endl << "Now [Enter] the height of the triangle: ";
    cin >> height;
    cout << "The area is: " << (base * height) / 2 << endl;
    break;

  default:
    cout << "Please [Enter] a valid selection next time." << endl;
    return 0;
  }
  system("pause"); // ... and here.
  return 0;
}

解决方案

You need to #include <cstdlib>

Source: http://en.cppreference.com/w/cpp/utility/program/system

Also, try to avoid system, it's dangerous. To pause the program when it's finished, put a breakpoint on the } at the end of main. There isn't a standard way to clear the screen unfortunately.

For future reference, the red squiggles are intellisense errors, which are shown by a different front-end than the one that actually compiles the code, so the red squiggles are sometimes wrong, especially with complex templates. In most cases, including this one, it's correct though.

这篇关于错误“系统”是模糊的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆