Fout “systeem” is dubbelzinnig?

Ik heb een eenvoudig programma en het werkt prima, maar de instructies system("CLS");en system("pause");hebben rode IntelliSense-regels onder hen. Als ik mijn cursor eroverheen beweeg, staat er Error "system" is ambiguous.Wat veroorzaakt dat?

Hier is mijn 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;
}

Antwoord 1, Autoriteit 100%

U moet #include <cstdlib>

Bron: http://en.cppreference.com/w/cpp/ utility / programma / systeem

Probeer ook te vermijden system, het is gevaarlijk. Om het programma te pauzeren wanneer het is voltooid, plaatst u een breekpunt op de }aan het einde van de main. Er is geen standaard manier om het scherm helaas te wissen.

Voor toekomstig referentie zijn de rode squiggels IntelliSense fouten, die worden getoond door een ander front-end dan degene die de code in feite compileert, zodat de rode squiggels soms verkeerd zijn, vooral met complex Sjablonen. In de meeste gevallen, inclusief deze, is het echter correct.

Other episodes