Error "system" is ambiguous?

c++, intellisense, visual-studio-2010

Solution

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.

Problem

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; } ```

Original source

Related problems