Oct 28, 2012 at 9:21pm UTC
How to copy 2d string array to txt file?
Oct 28, 2012 at 9:24pm UTC
1) By using a loop.
2) By using standard algorithms. For example there is standard algorithm that is named copy.:)
Last edited on Oct 28, 2012 at 9:25pm UTC
Oct 28, 2012 at 9:25pm UTC
Can you be more specific about algorithm? With 2 loops not work...
Oct 28, 2012 at 9:38pm UTC
I have this array...
If i put copy ( begin( X ), end( X ), ostream_iterator<char *>( cout, "\n" ) ); behind my array i get error....
expected constructor, destructor, or type conversion before '(' token
string X[14][5]= { {"Sati "," Ponedjeljak"," Utorak"," Srijeda", " Cetvrtak"},
{"7-8 "},
{"8-9 "},
{"9-10 "},
{"10-11"},
{"11-12"},
{"12-13"},
{"13-14"},
{"14-15"},
{"15-16"},
{"16-17"},
{"17-18"},
{"18-19"},
{"19-20"}};
Oct 28, 2012 at 10:07pm UTC
You have array of type std::string. I showed code for character arrays. If your compiler supports the range based for statement then you can write
1 2 3 4 5
for ( const auto &a : x )
{
for ( const auto &s : a ) std::cout << s << ' ' ;
std::cout << std::endl;
}
where instead of std::cout you shall use your file stream.
Last edited on Oct 28, 2012 at 10:09pm UTC