Hi all,
I am reading a text file and then computing some values. Then I am closing that file. Later on if i reopened that file in the same program I am unable to read that file. I found that the end of file is reached.
Here is the code: - ifstream file_ab;
-
string line;
-
file_ab.open("abc.txt", ios::in);
-
int Red,Green,Blue,count;
-
int (* 3darr)[128][128] = new int[128][128][128];
-
if (file_ab.is_open())
-
{
-
while (! file_ab.eof() )
-
{
-
int i=0,a[4]; //taken no of columns = 4
-
getline (file_ab,line);
-
istringstream tSS( line );
-
while( ! tSS.eof())
-
{
-
tSS>>a[i];
-
i++;
-
}
-
if(i>3)
-
{
-
Red=a[0] + 1;
-
Green=a[1] + 1;
-
Blue=a[2] + 1;
-
count = a[3];
-
3darr[relRed][relGreen][relBlue] = count;
-
}
-
}
-
file_ab.close();
-
}
-
else
-
cout << "Unable to open file";
-
-
file_ab.open("abc.txt", ios::in);
-
if (file_ab.is_open())
-
{
-
while (! file_ab.eof() )
-
{
-
int i=0,a[4]; //taken no of columns = 4
-
getline (file_ab,line);
-
istringstream tSS( line );
-
while( ! tSS.eof())
-
{
-
tSS>>a[i];
-
i++;
-
}
-
if(i>3)
-
{
-
Red=a[0] + 1;
-
Green=a[1] + 1;
-
Blue=a[2] + 1;
-
count = a[3];
-
3darr[relRed][relGreen][relBlue] = count;
-
}
-
}
-
file_ab.close();
-
}
-
else
-
cout << "Unable to open file";
in the first attempt, the file is read properly and i am able to display it.
But next time when I try to open the file I see that end of file is reached and the file is not read.
How can I read the same file again.
Please help.
Thanks!!
3 2556
Hi all,
I am reading a text file and then computing some values. Then I am closing that file. Later on if i reopened that file in the same program I am unable to read that file. I found that the end of file is reached.
Here is the code:
ifstream file_ab;
string line;
file_ab.open("abc.txt", ios::in);
int Red,Green,Blue,count;
int (* 3darr)[128][128] = new int[128][128][128];
if (file_ab.is_open())
{
while (! file_ab.eof() )
{
int i=0,a[4]; //taken no of columns = 4
getline (file_ab,line);
istringstream tSS( line );
while( ! tSS.eof())
{
tSS>>a[i];
i++;
}
if(i>3)
{
Red=a[0] + 1;
Green=a[1] + 1;
Blue=a[2] + 1;
count = a[3];
3darr[relRed][relGreen][relBlue] = count;
}
}
file_ab.close();
}
else
cout << "Unable to open file";
file_ab.open("abc.txt", ios::in);
if (file_ab.is_open())
{
while (! file_ab.eof() )
{
int i=0,a[4]; //taken no of columns = 4
getline (file_ab,line);
istringstream tSS( line );
while( ! tSS.eof())
{
tSS>>a[i];
i++;
}
if(i>3)
{
Red=a[0] + 1;
Green=a[1] + 1;
Blue=a[2] + 1;
count = a[3];
3darr[relRed][relGreen][relBlue] = count;
}
}
file_ab.close();
}
else
cout << "Unable to open file";
in the first attempt, the file is read properly and i am able to display it.
But next time when I try to open the file I see that end of file is reached and the file is not read.
How can I read the same file again.
Please help.
Thanks!!
Hi,
I have faced this issue in C.
I solved that my making the file pointer NULL after closing the file.
You can try the same approach, but i dont have idea bt that in C++
Raghuram
Try using file_ab.clear() before you close it. This will reset the EOF bit and allow you to read the file again. -
... // previous code
-
-
// Reset file flag bits and close the intput file, file_ab
-
file_ab.clear();
-
file_ab.close();
-
-
...// trailing code
-
Thanks for the answer.
It solved my problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: chuck amadi |
last post by:
By the way list is there a better way than using the readlines() to
> > >parse the mail data into a file , because Im using
> > >email.message_from_file it returns
> > >all the data i.e reads one...
|
by: MrFile |
last post by:
I added an app.config file to my application. (c#.net component dll)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="username" value="xx" />
<add...
|
by: Graham Taylor |
last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it
here also, as I think it might be the webserver which is causing my problem.
---------
I have an Access 2003 database...
|
by: gregsands |
last post by:
Hi
I have read all (ok most) of the posts relating to "Call to undefined
function mysql_connect()", read the manual on PHP.net and done
eveything thats ive been asked to do but cant get PHP to...
|
by: ranjeet |
last post by:
Hay Guys can you all suggest me the points on the below issue
Problem :
The thing is that I have the data some thing like this.
1486, 2168, 3751, 9074, 12134, 13944, 17983, 19173, 21190,...
|
by: Samuel M. Smith |
last post by:
I have been playing around with a subclass of dict wrt a recipe for
setting dict items using attribute syntax.
The dict class has some read only attributes that generate an
exception if I try to...
|
by: g35rider |
last post by:
Hi, I have the following code that is giving this error, I cant
simplify the code, I was just testing some theory for something we are
doing and was getting an issue here. Please someone point out...
|
by: WolfgangS |
last post by:
Ok first off, i am a total beginner at this groups stuff and i have no
clue how this works. This is probabaly the wrong group for my problem
but i will post it anyways. Learning by doing right?
...
|
by: Nyx18 |
last post by:
what im trying to do is read in a data from a file into 4 different arrays then also read in the same data using array of structs. the assignment is to show that we know how to use both methods of...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |