1

Have simple console application that builds fine:

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

It alsow builds fine if I add line #include <cstring> (or (and) #include <string>)

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

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

If I add file gc.c just with only one include line ,#include <cstring> (or (and) #include <string>), compiler generates a lot of errors:

Error   2   error C2061: syntax error : identifier 'using'  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  18  1   cstringerr
Error   43  error C2061: syntax error : identifier 'strxfrm'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  26  1   cstringerr
Error   41  error C2061: syntax error : identifier 'strtok' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  26  1   cstringerr
Error   39  error C2061: syntax error : identifier 'strstr' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   37  error C2061: syntax error : identifier 'strspn' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   35  error C2061: syntax error : identifier 'strrchr'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   33  error C2061: syntax error : identifier 'strpbrk'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   31  error C2061: syntax error : identifier 'strncpy'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   29  error C2061: syntax error : identifier 'strncmp'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   27  error C2061: syntax error : identifier 'strncat'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   25  error C2061: syntax error : identifier 'strlen' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   23  error C2061: syntax error : identifier 'strerror'   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   21  error C2061: syntax error : identifier 'strcspn'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   19  error C2061: syntax error : identifier 'strcpy' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   17  error C2061: syntax error : identifier 'strcoll'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   15  error C2061: syntax error : identifier 'strcmp' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   13  error C2061: syntax error : identifier 'strchr' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   11  error C2061: syntax error : identifier 'strcat' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   9   error C2061: syntax error : identifier 'memset' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   7   error C2061: syntax error : identifier 'memmove'    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   5   error C2061: syntax error : identifier 'memcpy' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   3   error C2061: syntax error : identifier 'memcmp' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  18  1   cstringerr
Error   4   error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  18  1   cstringerr
Error   6   error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   8   error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   10  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  20  1   cstringerr
Error   12  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   14  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   16  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  21  1   cstringerr
Error   18  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   20  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   22  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  22  1   cstringerr
Error   24  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   26  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   28  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  23  1   cstringerr
Error   30  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   32  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   34  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  24  1   cstringerr
Error   36  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   38  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   40  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  25  1   cstringerr
Error   42  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  26  1   cstringerr
Error   44  error C2059: syntax error : ';' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  26  1   cstringerr
Error   1   error C2054: expected '(' to follow 'using' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring  18  1   cstringerr

Looks like compiler does't understands anything that exists in include.

What is wrong with including <cstring> or <string> in additional cpp file?

2
  • BTW (not related to your compiler error), if you are using stdafx.h for precompiled headers, then stdafx.h must be the first file to include. Commented Oct 10, 2012 at 11:14
  • Yes, I have turned off precompiled headers Commented Oct 10, 2012 at 12:54

1 Answer 1

0

Go to Property

Properties > C/C++ > Advanced > Compile As and check Compile as C++ Code(/TP)

And allways make habit to include the file like this

#include "stdafx.h"    //Always include it first then other files.
#include <cstring>
Sign up to request clarification or add additional context in comments.

3 Comments

'Compile as C++ Code(/TP)' helped, but I suppose this is not a solution, because in some projects I will have both C and C++ libs. Why compiler acts in such a strange way?. I have turned off precompiled headers
@user1501700: I don't understand that. You are compiling gc.cpp, which is a cpp file (C++) and you are using the C++ include file cstring but you are complaining that this code does not compile as C?
My fall. I have gc.c, but not gc.cpp file. I have updated it in problem description

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.