Creating mixed c / C ++ code

I have a .cc file that uses both iostream and malloc . How can I compile this? using g++ , he says

  error: 'malloc' was not declared in this scope 

using gcc , he says

  fatal error: iostream: No such file or directory 

The source code is at http://sequitur.info/sequitur_simple.cc

UPDATE

I changed malloc to new and changed free to delete . However, I get a lot of errors. for instance

  /usr/include/c++/4.6/new:103:14: error: initializing argument 2 of รขvoid* operator new(std::size_t, void*)รข [-fpermissive] 
0
source share
3 answers

Either enable <stdlib.h> , or enable <cstdlib> and change malloc to std::malloc - compile with g++ . The inclusion of <cstdlib> is the preferred way for new C ++ code, the name.h style is deprecated in C ++.

While this will fix your problem, it might be better to switch to new / delete to be more consistent with C ++.

+5
source

You tried to turn on

 #include <stdio.h> #include <stdlib.h> 

and use g ++?

0
source

use new and delete in C ++ code. Do not mix new and malloc. From the code you posted, there is no reason AFAIK you cannot use new and delete

0
source

All Articles