I don't know whay but my for loop is not working.
I did this just to test and it gives the result i expect
//for(int a=0, f=1; f < vec.size();f++, a++)
//{
rel1 = vec.at(2);
rel2 = vec.at(3);
vector<string> relation = JoinRelation(rel1, rel2);
//}
so why does my for loop not work?
I want to get both vector elements until rel2 reaches the last vector element.
If i output the size of the relation vector i get a size of 0 but if i take it out of the for loop i get a size of 1
EDIT:
Just tried this which seems to make sense and compiles but i still get a vector size of 0. Also variables rel1 and rel2 both output values
for(int a=1; a < vec.size(); a++)
{
//if(f < vec.size())
//{
rel1 = vec.at(a-1);
rel2 = vec.at(a);
vector<string> relation = JoinRelation(rel1, rel2);
//}
}
If it helps here is my code
#include <fstream>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <stdio.h>
using namespace std;
std::vector<std::string> JoinRelation(std::string rel1, std::string rel2 )
{
std::string str;
std::vector<std::string> relation;
if((rel1=="<" && rel2=="=")||(rel1=="=" && rel2=="=")||(rel1=="!" && rel2=="=")||(rel1=="=" && rel2==">"))
rel1.append(rel2);
relation.push_back(rel1);
return relation;
}
int main()
{
string rel1,rel2;
vector <string> vec;
vector <string> relation;
vec.push_back("!");
vec.push_back("=");
vec.push_back("and");
vec.push_back("bee");
vec.push_back("=");
vec.push_back("=");
vec.push_back("car");
for(int a=0, f=1; a < vec.size(); a++,f++)
{
//if(f < vec.size())
//{
rel1 = vec.at(a);
rel2 = vec.at(f);
vector<string> relation = JoinRelation(rel1, rel2);
//}
}
cout << relation.size() << endl;
for(int b=0; b < relation.size(); b++)
{
cout << relation.at(b) << endl;
}
return 0;
}