I wrote the program kai.c and now am trying to compile it with gcc kai.c -o kai, which returns:

kai.c:5:18: fatal error: string: No such file or directory
 #include <string>
compilation terminated.

What can I do?

gcc version is: (Ubuntu 4.8.2-19ubuntu1) 4.8.2

closed as off-topic by Braiam, Florian Diesch, Richard, muru, αғsнιη Dec 1 '14 at 20:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Braiam, Florian Diesch, Richard, muru, αғsнιη
If this question can be reworded to fit the rules in the help center, please edit the question.

  • ... or replace <string> with <cstring> – αғsнιη Nov 28 '14 at 17:17
  • also program can not see library cstring – qwerty Nov 28 '14 at 17:21


The string library is the file string.h, so:

#include "string.h"


#include "string.h"
#include "stdio.h"

void main(){
    char src[2] = "Hi";
    char dest[2];
    strcpy(dest, src);
    printf("%s\n", dest); // Will print Hi

#include <string> is a C++ directive.

Rename your file to kai.cpp

And compile it with g++ kai.cpp -o kai

  • i need in c, because there is a fork(); – qwerty Nov 28 '14 at 17:17
  • 2
    @qwerty In c++ you also can have/use fork() – αғsнιη Nov 28 '14 at 17:58
  • @qwerty Everything from C is available in C++ (I think). If you want to use C++, use the g++ command instead of gcc to compile the code. g++ is the GNU C++ compiler, while gcc is the C compiler. On C, <string> in not available in C (if I'm not mistaken, all C headers end in .h). – user180409 Nov 28 '14 at 18:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.