2D vector

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;
}
}
}
}
Please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/
That formatting helps both reading and commenting.

You are creating a lot of threads that apparently lead nowhere. It would be more efficient for everyone (including you) if you would keep the discussion "together" in one thread.
thanks
Hello I have a problem with a twoD vector
this is my code

thanks:

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
#include <iostream>
#include <string>
#include <vector>

using namespace std;
 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()
{
	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;
			}			
		}
	}
}
Hi, I hope sombody can help me.
what is wrong doing that:

rama[j,i] = {factor[j], oper};

using curly brackets?
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.

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;
}
}
}
}
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
Still not to clear what you're trying to do, but perhaps something more like the following?

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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

std::vector<std::vector<std::string>> setRama(vector<string>, vector<string>);

int main()
{
    vector<string> fact = {"r", "M", "teta", "1", "2"};
    vector<string> operacion = {"+", "-", "*", "/", "^", "sin"};

    vector<vector<string>> rama = setRama(fact, operacion);

    return 0;
}

std::vector<std::vector<std::string>> setRama(vector<string> factor, vector<string> operacion)
{
    std::vector<std::vector<std::string>> rama(4, std::vector<std::string>(5));
    for(int j = 0; j < 4; j++)
    {
        for(int i = 0; i < 5; i++)
        {
            rama[j][i] = factor[j] + operacion[i];
            cout << "rama...= " << rama[j][i] << " j= " << j << " i= " << i << " oper " << operacion[i] << endl;
        }
    }

    return rama;
}


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
I think you are right
Topic archived. No new replies allowed.