error C3861: 'system': identifier not found

48,678

Solution 1

In C++, you have to include the appropriate header file that contains the declaration of a function in order to use it, otherwise you'll get a compiler error about the identifier not being found.

In the case of the system function, it is defined in the stdlib.h header file.

So, to the top of your code file (or in your precompiled header file), add the line

#include <stdlib.h>

(You use the angle brackets instead of quotation marks because stdlib.h is a header found in a place the build tool has been previously told about; this includes system header directories and other directories your build configuration specifically calls for.)

Aside from that, I strongly recommend against using either the Multi-Byte Character Set (all new Windows applications should support Unicode) or the system function, especially system("pause").

Solution 2

What worked for me was ensuring that the #include "stdafx.h" was the FIRST INCLUDE in the file. So #include <iostream> would therefore be after this.

Doing this solved the issue.

Share:
48,678
Sepideh Abadpour
Author by

Sepideh Abadpour

Updated on October 21, 2020

Comments

  • Sepideh Abadpour
    Sepideh Abadpour over 3 years

    I just started a new win32 console application in VS 2010 and set the Additional options property to precompiled headerin the upcoming wizard.

    Based on one of my previous questions I decided to use the following main prototype:

    int main(int argc,  char* argv[])
    

    I also changed the Character Set property of the project to Use Multi-Byte Character Set.

    But, the following code:

    system("pause");
    

    Will produce these two errors:

    error C3861: 'system': identifier not found  
    IntelliSense: identifier "system" is undefined
    

    I had the same experience before and there was no error!
    Can anyone suggest me what's wrong?