/*
Program:iterator Pass Str
compile:g++ main.cpp
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace Std;
Void Pass_str (const vector<vector<string> >::const_iterator &it_begin,
Const vector<vector<string> >::const_iterator &it_end)
{
Vector<vector <string> >::const_iterator it_i = it_begin;//First dimension vector range
Vector<vector<string> >::const_ Iterator it_i_end = it_end;
for (int i=0; it_i!= it_i_end; ++it_i) {
vector<string>::const_iterator it_j = (*it_i). Begin () ;//second dimension vector range
vector<string>::const_iterator it_j_end = (*it_i). end ();
for ( int j=0; It_j!= It_j_end; ++it_j) {
cout << *it_j << " ";
}
cout << Endl;
}
}
Main ()
{
string ia[12][12];
StringStream i_strm;
StringStream j_strm;
for (int i=0; i<12; ++i)//two-dimensional array initialization
{
I_strm.clear ()//Reset stream status Flag
I_strm.str ("");/empty flow content
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 ();
}
}
Two-dimensional vector initialization
vector<vector<string> > Vec_str (vector<string> (12));
for (I=0 i < vec_str.size (); i++) {
for (int j=0 J < Vec_str[i].size (); j + +) {
VEC_STR[I][J]=IA[I][J];
}
}
vector<vector<string> >::const_iterator it_begin = Vec_str.begin ();
vector<vector<string> >::const_iterator it_end = Vec_str.end ();
Pass_str (It_begin, it_end);
return 0;
}
/*
Program:template Pass Str
compile:g++ main.cpp
Note that you pass under the GNU compiler, and the VC compiler does not
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace Std;
Template <typename T, size_t M, size_t n>
void Pass_str (const T (& STR) [M][n]) {
cout << "\nthis is the output of template function:" << Endl;
for (size_t i = 0; i < M ++i) {
for (size_t j=0; j< N; ++j) {
cout << Str[i][j] << "";
}
cout << Endl;
}
}
int main ()
{
String ia[12][12];
StringStream I_STRM;
StringStream J_STRM;
for (int i=0; i<12; ++i)//two-dimensional array initialization
{
I_strm.clear ()//Reset stream status Flag
I_strm.str ("");/empty flow content
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 ();
}
}
PASS_STR (IA);
return 0;
}
/*
Program:c99 feature Pass Str
COMPILE:GCC Main.c-o Main-std=c99
by Nihui
*/
#include <stdio.h>
#include <string.h>
void pass_str1 (int m, int n, char* str[m][n])
{
printf ("This is the function & output:\n");
for (int i=0; i<m; ++i)
{
for (int j=0; j<n; ++j) {
if (j==0) {
printf ("\ n");
}
printf ("%s", Str[i][j]);
}
}
}
int main ()
{
const char name[] = "name";
Char x[] = "0 0";
Char y[] = "11 11";
Char z[] = "000";
char* ia[12][12] = {0};
for (int k=0; k<12; ++k)
{
Ia[0][k]=x;
}
for (int k=0; k<12; ++k)
{
Ia[11][k]=y;
}
for (int i=1; i<11; ++i)
{
for (int j=1; j<11; ++j)
Ia[i][j]=z;
}
PASS_STR1 (A, IA);
return 0;
}