Mar 23, 2019 at 3:18pm UTC
Hello I have a problem I think with the definition of a two dimention vector
the code is the following:
thanks
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void setRama(vector<string>, vector<string>);
vector<string> fact={"r","M","teta","1","2"};
vector<string> operacion={"+","-","*","/","^","sin"};
//vector<vector<string>> rama{4,5};
vector<vector<string>> rama;
string oper="";
int n=0;
int main()
{
/* symbol r("r"), M("M"), teta("teta");
ex g00 = 1-2.0/r;
*/
setRama(fact, operacion);
return 0;
}
void setRama(vector<string> factor,vector<string> operacion)
{
for(int j=0;j<=4;j++)
{
for(int i=0;i<=5;i++)
{
if(n==0)
{
oper="";
rama[j,i] = "(" + fact[j] + oper + ")";
cout<<"rama...=" << rama[j,i] << " j=" << j << " i=" << i << "oper"<<oper<<endl;
}
else
{
oper= operacion[i];
rama[j,i] = "(" + fact[j] + oper + ")";
cout<<"rama...=" << rama[j,i] << " j=" << j << " i=" << i << "oper"<<oper<<endl;
}
}
}
}
Mar 23, 2019 at 4:01pm UTC
Hi, I hope sombody can help me.
what is wrong doing that:
rama[j,i] = {factor[j], oper};
using curly brackets?
Mar 23, 2019 at 4:08pm UTC
vector<vector<string>> rama[4][5];
What exactly are you trying to accomplish here? It appears to me that you are trying to create a multidimensional array of vector<vector<string>>. Are you perhaps trying to create the vector<vector<string>> with sizes of 4 and 5?
rama[j,i] = {fact[j], oper};
Again what are you trying to accomplish here. It is so wrong I really don't understand what you're trying to do.
Also all of those global variables are not helping.
Mar 23, 2019 at 4:17pm UTC
Thank for answer
you are right I post my code:
[code:]
#include <iostream>
#include <string>
#include <vector>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
void setRama(vector<string>, vector<string>);
vector<string> fact={"r","M","teta","1","2"};
vector<string> operacion={"+","-","*","/","^","sin"};
//vector<vector<string>> rama{4,5};
vector<vector<string>> rama[4][5];
string oper="";
int n=0;
int main()
{
/* symbol r("r"), M("M"), teta("teta");
ex g00 = 1-2.0/r;
*/
setRama(fact, operacion);
return 0;
}
void setRama(vector<string> factor,vector<string> operacion)
{
for(int j=0;j<=4;j++)
{
for(int i=0;i<=5;i++)
{
if(n==0)
{
oper="";
rama[j][i] = {factor[j], oper};
cout<<"rama...=" << rama[j][i] << " j=" << j << " i=" << i << "oper"<<oper<<endl;
}
else
{
oper= operacion[i];
rama[j][i] = {factor[j], oper};
cout<<"rama...=" << rama[j][i] << " j=" << j << " i=" << i << "oper"<<oper<<endl;
}
}
}
}
Mar 23, 2019 at 4:20pm UTC
Thank for answer
you are right I post my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <iostream>
#include <string>
#include <vector>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
void setRama(vector<string>, vector<string>);
vector<string> fact={"r" ,"M" ,"teta" ,"1" ,"2" };
vector<string> operacion={"+" ,"-" ,"*" ,"/" ,"^" ,"sin" };
//vector<vector<string>> rama{4,5};
vector<vector<string>> rama[4][5];
string oper="" ;
int n=0;
int main()
{
/* symbol r("r"), M("M"), teta("teta");
ex g00 = 1-2.0/r;
*/
setRama(fact, operacion);
return 0;
}
void setRama(vector<string> factor,vector<string> operacion)
{
for (int j=0;j<=4;j++)
{
for (int i=0;i<=5;i++)
{
if (n==0)
{
oper="" ;
rama[j][i] = {factor[j], oper};
cout<<"rama...=" << rama[j][i] << " j=" << j << " i=" << i << "oper" <<oper<<endl;
}
else
{
oper= operacion[i];
rama[j][i] = {factor[j], oper};
cout<<"rama...=" << rama[j][i] << " j=" << j << " i=" << i << "oper" <<oper<<endl;
}
}
}
}
Last edited on Mar 23, 2019 at 4:25pm UTC
Mar 23, 2019 at 4:36pm UTC
but if you put
rama[j][i] = factor[j] + operacion[i];
you are summing factor[j] + operacion[i] and I don't want concatenate the strings
thanks