How can I change the output code page of cerr
Kelly Beard <[email protected]>
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <CAOvM2StvBdJWnkgjPzPKXiwuvROYmQ7Wk2OrkC_W8smsrOqmrw@mail.gmail.com> |
Given the following program
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
using namespace std;
void redirect(ostream& strm, ofstream& file)
{
// save output buffer of the stream
streambuf* strm_buffer = strm.rdbuf();
// redirect ouput into the file
strm.rdbuf (file.rdbuf());
}
int main(int argc, char* argv[])
{
string filename;
_CCSID_T ccsid(819);
filename = "redirect.log";
ofstream file(filename.c_str(), fstream::out | fstream::app, ccsid);
if (file.is_open()) {
redirect(cerr, file);
}
cerr << "This is some text to print out" << endl;
}
BTW, I usually live and breathe in the QSH environment.
How can I change the output code page of cerr to something besides 37,
which is probably the job's default? What happens here is when the program
is run, output is written to the file, but the program ends with "qsh:
001-0078 Process ended by signal 5.".
"cat redirect.log" prints garbage (EBCDIC)
"setccsid 37 redirect.log" fixes the problem and makes the text readable.
--
Kelly Beard
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.