473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Read Issue

Hi,

I am buried with the following issue on Linux platform, please let me know
if someone can help me out.

I am using ifstream to open and read the file, even i am able to open the
file i am NOT able to read the file contents.
The code i used is below.

fp = fopen(logFile, "a");
ifstream inFile;
inFile.open("/usr/local/cm/idp/test.txt");
if(!inFile.is_open())
{
fprintf(fp, "\n Unable to open the file");
}
else
{
fprintf(fp, "\n I can open the file");
}

std::string line;
getline (inFile, line);
fprintf("\nHi the Line is %s", line.c_str());
inFile.close();
fclose(fp);

It prints the following in my log file
I can open the file
Hi the Line is

The target file i.e. /usr/local/cm/idp/test.txt has all the permissions i.e.
777
Believe me the test.txt is not empty.
It used to work before but than it stopped working.

regards,
Venkat
Aug 18 '05 #1
1 1359
Venkat wrote:
Hi,

I am buried with the following issue on Linux platform, please let me know
if someone can help me out.

I am using ifstream to open and read the file, even i am able to open the
file i am NOT able to read the file contents.
The code i used is below.

fp = fopen(logFile, "a");
ifstream inFile;
inFile.open("/usr/local/cm/idp/test.txt");
if(!inFile.is_open())
{
fprintf(fp, "\n Unable to open the file");
}
else
{
fprintf(fp, "\n I can open the file");
}

std::string line;
getline (inFile, line);
You never test the state of the 'inFile' here. Why?
fprintf("\nHi the Line is %s", line.c_str());
Don't you mean

fprintf(fp, "\nHi the Line is %s", line.c_str());

? Which prompts me to ask you to post _real_ _complete_ code _and_
the file you're trying to read. Please do not expect us to test your
program reading file in /usr/local/... Presume the file is in the local
directory and use

ifstream inFile("test.txt");
inFile.close();
fclose(fp);

It prints the following in my log file
I can open the file
There should be an extra space before 'I'. Is there?
Hi the Line is

The target file i.e. /usr/local/cm/idp/test.txt has all the permissions i.e.
777
Believe me the test.txt is not empty.
It used to work before but than it stopped working.


What's changed?

Anyway, let's start over. Create a very simple program that opens your
file and attempts to read it. If it works, go back to your big program
and figure out what is different between them. If the very simple program
doesn't work, post it here. Completely. And the test file too. No
attachments, please.

V
Aug 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
23556
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
3
2692
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
40
61166
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
4
1863
by: Materialised | last post by:
Hi everyone, I have the following program #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp1, *fp2; char s;
6
2793
by: Cable | last post by:
Hello, I am hoping that someone can answer a question or two regarding file access. I have created an app that reads an image from a file then displays it (using OpenGL). It works well using...
7
22381
by: Eric | last post by:
I am trying to save the "last read" position of a file using a StreamReader object. I am reading the lines of the file using StreamReader.ReadLine and then saving the current position in the...
7
6032
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
15
2789
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
17
7988
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
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,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
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,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.