Skip to content

Instantly share code, notes, and snippets.

@justinrixx
Created April 2, 2015 17:25
Show Gist options
  • Save justinrixx/7db92ec2ac5b68dcdd27 to your computer and use it in GitHub Desktop.
Save justinrixx/7db92ec2ac5b68dcdd27 to your computer and use it in GitHub Desktop.
Given a text file, writes a file containing a cout statement which produces identical output through the output stream as reading the file in a text editor.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char ** argv)
{
if (argc != 3)
{
cout << "Usage: " << argv[0] << " inFilename outFilename" << endl;
return 0;
}
else
{
string s;
ifstream fin(argv[1]);
ofstream fout(argv[2]);
getline(fin, s);
fout << "cout << \"" << s << "\" << endl";
while (getline(fin, s))
fout << endl << "<< \"" << s << "\" << endl";
fout << " << endl;";
fin.close();
fout.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment