how to use poco to read text files

Please post support and help requests here.
dagg
Posts: 18
Joined: 28 Mar 2008, 09:07

how to use poco to read text files

Postby dagg » 07 Jul 2008, 14:53

I've tried with File, FileIOS, FileInputStream, FileOutputStream, FileStream, CountingIOS, CountingInputStream and CountingOutputStream
but no go, I'm pretty sure it exists, any help will be appriciated.

peter
Posts: 67
Joined: 11 Jul 2006, 16:26
Location: Austria

Re: how to use poco to read text files

Postby peter » 07 Jul 2008, 15:16

> I've tried with File, FileIOS, FileInputStream, FileOutputStream, FileStream, CountingIOS, CountingInputStream and CountingOutputStream
> but no go, I'm pretty sure it exists, any help will be appriciated.

Well,

some details would be nice...

Anway, FileInputStream should be good though, only difference to a standard ofstream is
the ability to open files where the file name contains unicode chars. Note that the FileInputStream constructor expects the filename to be UTF8 encoded.

br

Peter

dagg
Posts: 18
Joined: 28 Mar 2008, 09:07

Re: Re: how to use poco to read text files

Postby dagg » 08 Jul 2008, 11:02

ok, if I use FileInputStream how can I read a line? I've tried the

alex
Posts: 1282
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: Re: how to use poco to read text files

Postby alex » 08 Jul 2008, 15:26

> ok, if I use FileInputStream how can I read a line?

Code: Select all


std::string filename("C:\test.txt");
Poco::FileInputStream fis(filename);
std::string read;
fis >> read;
std::cout << read;

guenter
Posts: 1191
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: how to use poco to read text files

Postby guenter » 08 Jul 2008, 17:42

Well, the >> operator will only read up to the first whitespace.
You can try:

Code: Select all


Poco::FileInputStream fis("c:\test.txt");
std::string line;
std::getline(fis, line);


On Windows, line will probably contain a CR character (ASCII 13) at the end, which you should get rid off. Or use std: :ifstream, or Poco: :FileInputStream with a Poco::LineEndingConverter, as in:

Code: Select all


Poco::FileInputStream fis("c:\test.txt");
Poco::InputLineEndingConverter lec(fis, Poco::LineEnding::NEWLINE_LF);
std::string line;
std::getline(lec, line);

dagg
Posts: 18
Joined: 28 Mar 2008, 09:07

Re: Re: how to use poco to read text files

Postby dagg » 08 Jul 2008, 19:19

> Well, the >> operator will only read up to the first whitespace.
> You can try:
>

Code: Select all


> Poco::FileInputStream fis("c:\test.txt");
> std::string line;
> std::getline(fis, line);
>

>
> On Windows, line will probably contain a CR character (ASCII 13) at the end, which you should get rid off. Or use std: :ifstream, or Poco: :FileInputStream with a Poco::LineEndingConverter, as in:
>
>

Code: Select all


> Poco::FileInputStream fis("c:\test.txt");
> Poco::InputLineEndingConverter lec(fis, Poco::LineEnding::NEWLINE_LF);
> std::string line;
> std::getline(lec, line);
>


thanks, it worked like a charm :)


Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest

cron