i am quite new to c so i have an assignement and trying to experiment a bit before tackling the process of building an AST tree. Trying to input a string expressing (operator and operands ) and splitting it as in the python split but it seems i keep getting either basic class structure problems or compilation problems not sure .
expr.h file
#include <string>
class BuildAst
{
public:
void build(std::string expr);
protected:
char opera;
char left_child;
char right_child;
};
expr.cpp file
#include "expr.h"
#include <string>
#include <string.h>
#include <iostream>
#include <sstream>
void BuildAst::build(std::string expr)
{
std::string str1, str2;
std::stringstream s(expr);
s>>str1>>str1;
std::cout<<str1<<std::endl;
std::cout<<str2<<std::endl;
};
main.cpp file
#include "expr.h"
#include <vector>
#include <string>
#include <iostream>
int main() {
std::string s;
std::cout << "Enter the expression\n";
std::cin >> s;
BuildAst ast;
ast.build(s);
};
makefile
CFLAGS="--std=c 14"
all: main tests
expr:
$(CC) $(CFLAGS) -c -o expr.o expr.cpp
main: expr
$(CC) $(CFLAGS) -o expr main.cpp expr.o
tests: expr
$(CC) $(CFLAGS) -o tests testcases.cpp expr.o
clean:
rm *.o expr tests
The input expression i'm trying to use is 3 5 and output should be 3,5 And i keep getting the following errors
Tried adding to the 3 files (main.cpp/ expr.cpp/expr.h)
#define _GLIBCXX_USE_CXX11_ABI 0/1
then the error i am getting changed to
Could you help me please and thank you.
CodePudding user response:
I had a similar question to this a while back. The answer that robthebloke had answered perfectly for me. Not sure if this is as applicable for you, but my post is linked HERE.
CodePudding user response:
okay, turned out i'm not running the files as a project in codeblocks. Problem fixed