Skip to content

Instantly share code, notes, and snippets.

@blippy
Last active June 19, 2016 10:12
Show Gist options
  • Save blippy/f939686e858f4f7103c7035e1f62c035 to your computer and use it in GitHub Desktop.
Save blippy/f939686e858f4f7103c7035e1f62c035 to your computer and use it in GitHub Desktop.
Example of writing to cout or filename
#include <fstream>
#include <iostream>
void prin_vecvec(vecvec_t & vvs, const char *sep, const char *recsep, const char *filename )
{
std::ofstream ofs;
bool use_file = strlen(filename);
if(use_file) ofs.open(filename, std::ofstream::out);
ostream &os = use_file ? ofs : cout ;
string ssep = string(sep);
int i;
for(i=0; i< vvs.size(); i++) {
vector<string> v = vvs[i];
int j, len;
len = v.size();
if(len == 0) continue;
for(j=0; j<len; j++) {
os << v[j];
if(j+1<len) os << ssep;
}
if(len>0) os << recsep ;
}
if(use_file) ofs.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment