So I want to use string class
and multiset template
of C++.
My original code interfaces from Python
to C
using ctypes
and now I am trying to interface C
to C++
. (If there is any direct interfacing between Python
& C++
, I would welcome the suggestion but scanning through a couple of Stack Overflow and Stack Exchange, I found this method to be more feasible.
@n.m in comments provided solution to this, but I would still like to know if it is possible to interface C & C++ for educational purpose)
So here is a simple example to reproduce what happens when I try to merge with string class...
ex.c
#include <stdio.h>
#include <stdlib.h>
void cppstr(char *);
void str(char *x) {
cppstr(x);
}
int main() {
char *x;
x = (char *)malloc(sizeof(char)*1024);
str(x);
return 0;
}
Above is my c file.
ex.cpp
#include <string>
#include <cstring>
using namespace std;
extern "C" void cppstr(char *s) {
string x = "HELLO" + "WORLD";
strcpy(s, x.c_str());
}
Above is cpp File.
If I compile using gcc
or g++
, it doesn't compile and instead gives linker errors related to string.
compiler ex.c ex.cpp
What is a solution for string and multiset both?