#include<string>
#include<vector>
#include<iostream>
using namespace std;
void main()
{
vector<string> v;
string s="one";
v.push_back(s);
s="two";
v.push_back(s);
s="three";
v.push_back(s);
for(int i=0;i<v.size();++i)
cout<<v[i]<<'/n';
}
输出:
one
two
three
Press any key to continue
4-8
#include<string>
#include<list>
#include<algorithm>
#include<iostream>
using namespace std;
void write(const string& s)
{
cout<<s<<'/n';
}
void main()
{
list<string> lst;
string s="knife";
lst.push_front(s);
s="fork";
lst.push_front(s);
s="spoon";
lst.push_front(s);
for_each(lst.begin(),lst.end(),write);
}
输出:
spoon
fork
knife
Press any key to continue