Hi,
i am storing data read from some file (text,pdf,gif...) into std::list
using push_back function available for list.
and my list type is string.( std::list<string> mylist)
after storing whole file in list i am trying to writing the data stored
in list into new file of same format.
if the source file is text then destination new file obtained is
correct but if it is pdf then the destination file obtained is not
correct, even size is less than the original file.
i am opening the file using fopen() call in BInary Mode always..
well, if i write the data without using the std::list, i am getting the
expected correct results.
i am worrying why this is not working in case of std::list if data is
non textual..
if anybody is having any idea i will really appreciate the response.
thanks,
Munish 8 3254
"emanshu" <mu*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com... Hi,
i am storing data read from some file (text,pdf,gif...) into std::list using push_back function available for list. and my list type is string.( std::list<string> mylist) after storing whole file in list i am trying to writing the data stored in list into new file of same format. if the source file is text then destination new file obtained is correct but if it is pdf then the destination file obtained is not correct, even size is less than the original file.
i am opening the file using fopen() call in BInary Mode always..
well, if i write the data without using the std::list, i am getting the expected correct results. i am worrying why this is not working in case of std::list if data is non textual..
if anybody is having any idea i will really appreciate the response.
You have a bug on line 42. Fix it.
-Mike
emanshu wrote: Hi,
i am storing data read from some file (text,pdf,gif...) into std::list using push_back function available for list. and my list type is string.( std::list<string> mylist) after storing whole file in list i am trying to writing the data stored in list into new file of same format. if the source file is text then destination new file obtained is correct but if it is pdf then the destination file obtained is not correct, even size is less than the original file.
i am opening the file using fopen() call in BInary Mode always..
well, if i write the data without using the std::list, i am getting the expected correct results. i am worrying why this is not working in case of std::list if data is non textual..
if anybody is having any idea i will really appreciate the response.
thanks, Munish
Can you post the code for your read and write routines? Also, the
preferred file handling methods for C++ are fstreams not FILEs.
Cheers! --M
Hi,
here is the code snipplets..
int i=0;
while( i < Source_File_Size){
bytesread=readFile(buff, 1400);
i=i+bytesread;
mylist.push_back(buff);
}
openFile(NewFileName in Binary mode){
std::string buff;
std::list<std::string>::const_iterator rcv it;
for (it.begin() to it.end()){
buff=*it;
writeFile(buff,buff.length());
}
this code snipplets generate the new file correctly if data is
textual...but does not generate correct data if it is binary..
case2:
also, if i do fow:
while( i < Source_File_Size){
bytesread=readFile(buff, 1400);
i=i+bytesread;
writeNewfile(buff,bytesread);
}
in case 2 i am not using std::list rather i am directly writing to file
the data read. and this code creates new file correctly for all types
of data(text,pdf,img..)
please help...
thanks,
munish
emanshu wrote: Hi,
here is the code snipplets.. int i=0;
while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; mylist.push_back(buff); }
openFile(NewFileName in Binary mode){ std::string buff; std::list<std::string>::const_iterator rcv it; for (it.begin() to it.end()){ buff=*it; writeFile(buff,buff.length()); } this code snipplets generate the new file correctly if data is textual...but does not generate correct data if it is binary..
case2: also, if i do fow: while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; writeNewfile(buff,bytesread); } in case 2 i am not using std::list rather i am directly writing to file the data read. and this code creates new file correctly for all types of data(text,pdf,img..)
please help...
thanks, munish
What does readFile do? What does writeNewFile do? What type and size is
buff? etc. etc. If you post the actual code, we can provide a lot more
help.
Cheers! --M
emanshu wrote: Hi,
i am storing data read from some file (text,pdf,gif...) into std::list using push_back function available for list. and my list type is string.( std::list<string> mylist) after storing whole file in list i am trying to writing the data stored in list into new file of same format. if the source file is text then destination new file obtained is correct but if it is pdf then the destination file obtained is not correct, even size is less than the original file.
i am opening the file using fopen() call in BInary Mode always..
well, if i write the data without using the std::list, i am getting the expected correct results. i am worrying why this is not working in case of std::list if data is non textual..
if anybody is having any idea i will really appreciate the response.
thanks, Munish
BTW, you probably don't want to use std::string for this purpose. Try
std::vector<char> instead.
Cheers! --M
emanshu wrote: Hi,
here is the code snipplets.. int i=0;
while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; mylist.push_back(buff); }
openFile(NewFileName in Binary mode){ std::string buff; std::list<std::string>::const_iterator rcv it; for (it.begin() to it.end()){ buff=*it; writeFile(buff,buff.length()); } this code snipplets generate the new file correctly if data is textual...but does not generate correct data if it is binary..
case2: also, if i do fow: while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; writeNewfile(buff,bytesread); } in case 2 i am not using std::list rather i am directly writing to file the data read. and this code creates new file correctly for all types of data(text,pdf,img..)
Hello emanshu!
I didn't manage to understand 100% of what you are doing here. If in the
first while loop you are using a normal char array this might be the
problem. When pushing that char array into the list, it is handles as
zero terminated c-string. And every now and then you are missing data.
Just an idea...
CU,
Daniel Kay
Daniel Kay wrote: emanshu wrote:
Hi,
here is the code snipplets.. int i=0;
while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; mylist.push_back(buff); }
openFile(NewFileName in Binary mode){ std::string buff; std::list<std::string>::const_iterator rcv it; for (it.begin() to it.end()){ buff=*it; writeFile(buff,buff.length()); } this code snipplets generate the new file correctly if data is textual...but does not generate correct data if it is binary..
case2: also, if i do fow: while( i < Source_File_Size){ bytesread=readFile(buff, 1400); i=i+bytesread; writeNewfile(buff,bytesread); } in case 2 i am not using std::list rather i am directly writing to file the data read. and this code creates new file correctly for all types of data(text,pdf,img..)
Hello emanshu!
I didn't manage to understand 100% of what you are doing here. If in the first while loop you are using a normal char array this might be the problem. When pushing that char array into the list, it is handles as zero terminated c-string. And every now and then you are missing data. Just an idea...
Good idea too.
The correct code is
mylist.push_back(std::string(buff, bytesread));
That will make sure that the string pushed onto the list has the correct
length.
If you look at you original code there is nowhere that you have told the
list what the length of your data is, so that should have been a clue
that something was wrong.
john CU, Daniel Kay
Hi John,
yes, your comment works for me...
thanks a lot for your help..
Munish Nayyar
emanshu " Innovative MInd" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Pemberton |
last post by:
I'm sure there's a good explanation for this effect, but I get rather
a strange output from this little test:
#include <iostream>
#include <list>
int main()
{
std::list<int> int_list;
|
by: Jef Driesen |
last post by:
The number of items in my std::list is changed after sorting (using
std::list member function sort). I'm using MSVC6 and the actual (pseudo)
code is posted below. The output from size() is...
|
by: Josh Mcfarlane |
last post by:
Just out of curiosity:
When would using std::list be more efficient / effective than using
other containers such as vector, deque, etc?
As far as I'm aware, list doesn't appear to be...
|
by: alex221 |
last post by:
In need to implement a tree structure in which every node has arbitrary
number of children the following code has come into mind:
using std::list;
template < class Contents class Tree_node{
...
|
by: Spoon |
last post by:
Hello,
Could someone explain why the following code is illegal?
(I'm trying to use a list of (C-style) arrays.)
#include <list>
typedef std::list < int foo_t;
int main()
{
int v = { 12, 34...
|
by: Javier |
last post by:
Hi all,
I have this code:
class A
{
std::list<Bm_observadores;
void function()
{
|
by: Ray D. |
last post by:
Hey all,
I'm trying to pass a list into a function to edit it but when I
compile using g++ I continue to get the following error:
maintainNeighbors.cpp:104: error: invalid initialization of...
|
by: isliguezze |
last post by:
template <class T>
class List {
public:
List();
List(const List&);
List(int, const T&);
void push_back(const T &);
void push_front(const T &);
void pop_back();
|
by: Isliguezze |
last post by:
Does anybody know how to make a wrapper for that iterator? Here's my
wrapper class for std::list:
template <class Tclass List {
private:
std::list<T*lst;
public:
List() { lst = new...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |