错误"system"模棱两可?
Error "system" is ambiguous?
我有一个简单的程序,它工作得很好,但是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语句末尾的}
上放置一个断点。遗憾的是,目前还没有清除屏幕的标准方法。
为将来参考,红色曲线表示智能感知错误,这些错误是由与实际编译代码的前端不同的前端显示的,因此红色曲线有时是错误的,特别是对于复杂的模板。在大多数情况下,包括这个,这是正确的
相关文章:
- 如何在c++中使用system()来运行包含空格的python脚本
- System.InvalidCastException - SQL to C++ - safe_cast<float>
- "Inverse SFINAE"避免模棱两可的过载
- 操作员C++的模棱两可的过载
- 模棱两可的重载模板
- C++/CLI System.AccessViolation在托管类中调用非托管函数时出现异常
- 来自 Android 应用程序内部的 boost 类型的 boost::wrapexcept<boost::system::system_error> 的未捕获异常
- 调用重载的"<大括号括起来的初始值设定项列表>"对于对来说就足够了是模棱两可的
- 程序在使用 system() 启动另一个可执行文件时停止
- 为什么我的 DeviceInformation 对象没有 System.Devices.InterfaceClassGuid 属性?
- 为什么"using System;"不被视为不良做法?
- C++ 合并字符串以'system'函数错误
- 模棱两可的 != reverse_iterator运算符
- SFINAE不能防止模棱两可的操作员过载吗?
- VSCode 说 std::chrono 是模棱两可的,如果运算符<<重载
- System.AccessViolationException:shared_ptr C# .NET 和 C++ 应用程
- 为什么对模板的调用不模棱两可?
- 修复重载运算符的使用'+'模棱两可?
- 为什么同时覆盖全局新运算符和特定于类的运算符不是模棱两可的行为?
- 错误"system"模棱两可?