std::string file("testfile.txt");
Poco::FileOutputStream fos(file);
fos << "sometestdata";
fos.close();
Poco::FileInputStream fis(file);
std::string read;
fis >> read;
petervn wrote:Does the example you've given read UTF-8 encoded arabic characters? Or russian?
petervn wrote: I'd poked around Poco I/O libraries and the examples and found a StreamConverter class that is supposed to automatically convert UTF-8 representation to some other encoding based on the parameters passed to the class constructor.
UTF8Encoding utf8Encoding;
Latin1Encoding latin1Encoding;
std::ifstream istr(file);
std::ostringstream ostr;
InputStreamConverter converter(istr, utf8Encoding, latin1Encoding);
StreamCopier::copyStream(converter, ostr);
petervn wrote:Not sure if I am on the right path, though...
Will ifstream work with FTP or HTTP streams? We frequently use Poco streams to download data from FTP sites or an HTTP servers, so it is not possible for us to use streams that can only deal with local files.
Poco::UTF8Encoding utf8;
Poco::UTF16Encoding utf16;
Poco::FileInputStream fs ("someUTF_8_encoded_file.txt");
Poco::InputStreamConverter conv(fs, utf8, utf16);
std::streambuf& rdbuf = *conv.rdbuf();
while (conv.good())
{
wchar_t wctemp;
char *p = (char*)&wctemp;
*p++ = rdbuf.sbumpc();
*p++ = rdbuf.sbumpc();
wprintf(L"%c", wctemp);
}
alex wrote:petervn wrote:Does the example you've given read UTF-8 encoded arabic characters? Or russian?
Yes. But it appears that you say read but actually mean convert.petervn wrote: I'd poked around Poco I/O libraries and the examples and found a StreamConverter class that is supposed to automatically convert UTF-8 representation to some other encoding based on the parameters passed to the class constructor.
That's a different issue. If you want to convert the file content to another encoding, then yes, you'll want to use a stream converter, something like this:
- Code: Select all
UTF8Encoding utf8Encoding;
Latin1Encoding latin1Encoding;
std::ifstream istr(file);
std::ostringstream ostr;
InputStreamConverter converter(istr, utf8Encoding, latin1Encoding);
StreamCopier::copyStream(converter, ostr);petervn wrote:Not sure if I am on the right path, though...
Will ifstream work with FTP or HTTP streams? We frequently use Poco streams to download data from FTP sites or an HTTP servers, so it is not possible for us to use streams that can only deal with local files.
All Poco streams inherit from std streams and FTPStreamFactory::open() returns std::istream pointer , so yes you should be able to copy and convert between them.
petervn wrote:I've had some issues trying to use operations such as ungetc but I got around it by maintaining my own internal cache.
Users browsing this forum: No registered users and 1 guest