[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
<g++ 3.4.4> Problem with reading file into string
From: |
alexvn |
Subject: |
<g++ 3.4.4> Problem with reading file into string |
Date: |
9 Aug 2005 05:20:15 -0700 |
User-agent: |
G2/0.2 |
Hi,
Here are two functions that read text and binary file into string.
// --------------------------------------
string txt_file_to_string ()
{
ostringstream oss;
fs_infile_txt.clear();
fs_infile_txt.seekg (0, ios::beg);
vector<char> v (infile_txt_filesize);
fs_infile_txt.read(&v[0], infile_txt_filesize);
ostream_iterator<char> out(oss);
copy (&v[0], &v[v.size()], out);
return oss.str();
}
string bin_file_to_string ()
{
ostringstream oss;
fs_infile_bin.clear();
fs_infile_bin.seekg (0, ios::beg);
vector<char> v (infile_bin_filesize);
fs_infile_bin.read(&v[0], infile_bin_filesize);
ostream_iterator<char> out(oss);
copy (&v[0], &v[v.size()], out);
return oss.str();
}
// --------------------------------------
There is no problem with those functions with
g++ 3.3.3 on Cygwin,
gpp 3.4.1 on Djgpp,
gpp 4.0.1 on Djgpp.
But there is a problem with txt_file_to_string () while using
g++ 3.4.4 on Cygwin
P.S. There is no problem with bin_file_to_string () while using
g++ 3.4.4 on Cygwin
Full test file xxx2.cpp is at
http://groups.google.com/group/test-av/msg/6fa382a8feb737c1
Here are results of the running:
====== Run-1 (OK) ======
$ a 1023
YOUR COMMAND LINE : a 1023
### File size : 1023
mbuffer size = 1024
Sizes :
infile_content.size() = 1023
str_txt.size() = 1023
str_bin.size() = 1023
str_iss.size() = 1023
OK! infile_content == str_txt
OK! infile_content == str_bin
OK! infile_content == str_iss
========================
====== Run-2 (Problem) ======
$ a 1024
YOUR COMMAND LINE : a 1024
### File size : 1024
mbuffer size = 1025
Sizes :
infile_content.size() = 1024
str_txt.size() = 1024
str_bin.size() = 1024
str_iss.size() = 1024
WARNING! infile_content != str_txt
--- Different strings ---
str1.size() = 1024, str2.size() = 1024
str1[1018] = <Y>; str2[1018] = <S>
str1[1019] = <Z>; str2[1019] = <T>
str1[1020] = <A>; str2[1020] = <U>
str1[1021] = <B>; str2[1021] = <V>
str1[1022] = <C>; str2[1022] = <W>
str1[1023] = <D>; str2[1023] = <X>
-------------------------
OK! infile_content == str_bin
OK! infile_content == str_iss
=============================
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
- <g++ 3.4.4> Problem with reading file into string,
alexvn <=