Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why I get error: 'strcmp': identifier not found (visual studio 2010)

Tags:

c

why do i get error: 'strcmp': identifier not found in visual studio 2010 C++ Express

#include <string.h>
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    printf("%d",(int)strcmp( "str1", "str2" ));

    return 0;
}

Thanks

like image 203
Ben Avatar asked Sep 13 '10 21:09

Ben


1 Answers

:( #include <string.h> :(
#include "stdafx.h"

Fun quirk of the MSVC compiler, it generates the exact same error when you compile it like that. Yes, not a lot of 'fun'. It skips everything to find the stdafx.h precompiled header include directive. The string.h doesn't actually get included. Fix:

#include "stdafx.h"
#include <string.h>

Always put the stdafx.h include first.

like image 89
Hans Passant Avatar answered Nov 13 '22 13:11

Hans Passant