Why not a vector of vectors (of vectors...)? Your profiling indicated performance requirement issues?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Hmm. Let me try this.
#include <iostream>
#include <vector>
int main()
{
std::vector<int> row;
std::vector<std::vector<int> > array2d;
row.push_back(1);
row.push_back(2);
row.push_back(3);
array2d.push_back(row);
row.clear();
row.push_back(4);
row.push_back(5);
array2d.push_back(row);
row.clear();
row.push_back(6);
row.push_back(7);
row.push_back(8);
row.push_back(9);
array2d.push_back(row);
for ( std::vector<std::vector<int> >::iterator it = array2d.begin(); it != array2d.end(); ++it )
{
for ( std::vector<int>::iterator jt = it->begin(); jt != it->end(); ++jt )
{
std::cout << *jt << ' ';
}
std::cout << std::endl;
}
return 0;
}
/* my output
1 2 3
4 5
6 7 8 9
*/
Likely someone will later come along and point out issues.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
std::vector<std::vector<int> >
Kaza, your problem from before might have been that you didn't have a space between these two right angle brackets. You need a space. Without a space, the angle brackets get interpreted as a '>>' operator.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
I hope you noticed my other comment.
'std' is a namespace, not a class. When using headers with names like instead of , you need to use it. You can put 'using namespace std;' in your program to avoid having to write 'std' everywhere. You could also write 'using std::vector;' to throw out the requirement that std:: be used in front of 'vector'. I think the latter method, of importing names one by one, is better, because later, the standard library might be expanded, and you don't want names of new standard library objects to collide with ones you're using. (That's what happens with wanton disuse of the namespaces).
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
Is the std class identifier preceding the methods/templates that important?
Very much so. Pay close attention to the top part of [post=122322]this[/post], where 3 methods are described. [edit]Or [post=97182]this[/post].
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314