|
发表于 2009-12-9 08:25:53
|
显示全部楼层
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- using namespace std;
- void pass_str4(const vector< vector<string> >::const_iterator &it_begin, const vector< vector<string> >::const_iterator &it_end)
- {
- cout << "this is the function vector output:" << endl;
-
- vector<vector<string> >::const_iterator it1 = it_begin;
- vector<vector<string> >::const_iterator it1_end = it_end;
- for( ; it1 != it1_end; ++it1 ) {
- // it1 is an iterator, *it1 is the vector<string> of vector< vector<string> >
- vector<string>::const_iterator it2 = (*it1).begin();
- vector<string>::const_iterator it2_end = (*it1).end();
- for ( ; it2 != it2_end; ++it2 ) {
- // it2 is an iterator, *it2 is the string of vector<string>
- cout << *it2 << '\t';
- }
- cout << endl;
- }
- }
- int main(int argc, char* argv[])
- {
- string ia[12][12];
- stringstream i_strm;
- stringstream j_strm;
-
- for(int i=0; i<12; ++i)
- {
- i_strm.clear();
- i_strm.str("");
- i_strm << i;
- for(int j=0; j<12; ++j){
- j_strm.clear();
- j_strm.str("");
- j_strm << j;
- ia[i][j]=i_strm.str()+" "+j_strm.str();
- }
- }
-
- // represent array as vector
- vector< vector<string> > vec_str(12, vector<string>(12));
- for(int i=0; i < vec_str.size(); i++){
- for(int j=0; j < vec_str[i].size(); j++){
- vec_str[i][j]=ia[i][j];
- }
- }
-
- pass_str4(vec_str.begin(), vec_str.end());
-
- // print vector content
- for(int i=0; i < 12; ++i){
- for(int j=0; j < 12; ++j){
- cout << vec_str[i][j] << '\t';
- }
- cout << endl;
- }
-
- return 0;
- }
复制代码 |
|