I just started to study c++ and I did not get to understand the list. I have some code using the array.
#include <iostream>
#include <string>
using namespace std;
class test {
public:
string a,b;
};
int main(){
test param [3];
param[0].a = "asdf";
param[0].b = "ghjk";
param[1].a = "qwer";
param[1].b = "tyui";
param[2].a = "zxcv";
param[2].b = "vbnm";
cout << "param\ta\tb\n";
for(int i = 0; i<3; i++){
cout << i << "\t" << param[i].a <<
"\t" << param[i].b << endl;
}
}
How to realize same code using the list? Below are my attempts to do this:
#include <list>
...
list <test> param;
param.push_back();
param.back().a = "asdf";
param.back().b = "ghjk";
...
second try:
...
test o;
o.a = "asdf"; o.b = "ghjk";
param.push_back(o);
...
As you know, none of them works...
std::listinstead ofstd::vector?