#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void writeCharsetToFile(const string& filename);
void outputFile(const string& filename);
int _tmain(int argc, _TCHAR* argv[])
{
writeCharsetToFile("charset.out");
outputFile("charset.out");
system("pause");
return 0;
}
void writeCharsetToFile(const string& filename)
{
//open output file
ofstream file(filename.c_str());
//file opened?
if(!file){
//No, abort program
cerr<<"can't open output file/""<<filename<<"/""<<endl;
exit(EXIT_FAILURE);
}
//write character set
for(int i=32;i<256;i++)
{
file<<"value: "<<setw(3)<<i<<" "
<<"char: "<<static_cast<char>(i)<<endl;
}
}//close file automatically
void outputFile(const string& filename)
{
//open input file
ifstream file(filename.c_str());
//file opened?
if(!file){
//No,abort program
cerr<<"can't open input file/""<<filename<<"/""<<endl;
exit(EXIT_FAILURE);
}
//copy file contents to cout
char c;
while(file.get(c)) { cout.put(c);}
}//close file automatically