000*_*000 1 c++ intellisense visual-studio-2010
我有一个简单的程序,它工作正常,但system("CLS");和system("pause");语句下面有红色的IntelliSense线.当我将光标移到它们上面时,它会说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;
}
Run Code Online (Sandbox Code Playgroud)
Moo*_*uck 10
你需要 #include <cstdlib>
资料来源:http://en.cppreference.com/w/cpp/utility/program/system
另外,尽量避免system,这很危险.要在程序结束时暂停程序,请}在main的末尾放置一个断点.遗憾的是,没有标准的方法来清除屏幕.
为了将来参考,红色波浪线是智能感知错误,它们由与实际编译代码的前端不同的前端显示,因此红色波形有时是错误的,特别是对于复杂的模板.在大多数情况下,包括这个,但它是正确的.
| 归档时间: |
|
| 查看次数: |
31426 次 |
| 最近记录: |