错误"system"模棱两可?

Error "system" is ambiguous?

本文关键字:模棱两可 system 错误      更新时间:2023-10-16

我有一个简单的程序,它工作得很好,但是system("CLS");system("pause");语句在它们下面有红色的智能感知行。当我把光标移到它们上面时显示的是Error "system" is ambiguous.是什么原因?

下面是我的代码:
#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;
}

您需要#include <cstdlib>

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

同时,尽量避免system,这是危险的。要在程序完成时暂停程序,请在main语句末尾的}上放置一个断点。遗憾的是,目前还没有清除屏幕的标准方法。

为将来参考,红色曲线表示智能感知错误,这些错误是由与实际编译代码的前端不同的前端显示的,因此红色曲线有时是错误的,特别是对于复杂的模板。在大多数情况下,包括这个,这是正确的