hi
I have a code, the part which is troubling goes like this
*************** *************** *************** *************** ****
#include <istream>
#include <ostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
....
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
....
when run into the debugger "gdb" it shows "closed", however it prints
"p f_name" fine and if I take that and copy it to the command line
"cat /full/path/to/file" it prints out. the permission on that file is
-rw-r--r--
many thanks 6 4761
Gary Wessle wrote:
I have a code, the part which is troubling goes like this
*************** *************** *************** *************** ****
#include <istream>
#include <ostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
...
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
...
when run into the debugger "gdb" it shows "closed", however it prints
"p f_name" fine and if I take that and copy it to the command line
"cat /full/path/to/file" it prints out. the permission on that file is
-rw-r--r--
"permission s" are OS-specific. "Debuggers" are tools and OS-specific.
Please post OS-speficic inquiries to the newsgroup dedicated to that OS.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Victor Bazarov" <v.********@com Acast.netwrites :
Gary Wessle wrote:
I have a code, the part which is troubling goes like this
*************** *************** *************** *************** ****
#include <istream>
#include <ostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
...
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
...
when run into the debugger "gdb" it shows "closed", however it prints
"p f_name" fine and if I take that and copy it to the command line
"cat /full/path/to/file" it prints out. the permission on that file is
-rw-r--r--
"permission s" are OS-specific. "Debuggers" are tools and OS-specific.
Please post OS-speficic inquiries to the newsgroup dedicated to that OS.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
well, the code I posted will print "closed" where I expected it to
print out "is open".
the statements about the gdb and permissions are just to show that I
did some homework.
Gary Wessle <ph****@yahoo.c omwrites:
"Victor Bazarov" <v.********@com Acast.netwrites :
Gary Wessle wrote:
I have a code, the part which is troubling goes like this
>
>
*************** *************** *************** *************** ****
#include <istream>
#include <ostream>
#include <fstream>
>
using std::ifstream;
using std::ofstream;
>
>
>
...
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
...
>
when run into the debugger "gdb" it shows "closed", however it prints
"p f_name" fine and if I take that and copy it to the command line
"cat /full/path/to/file" it prints out. the permission on that file is
-rw-r--r--
"permission s" are OS-specific. "Debuggers" are tools and OS-specific.
Please post OS-speficic inquiries to the newsgroup dedicated to that OS.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
well, the code I posted will print "closed" where I expected it to
print out "is open".
the statements about the gdb and permissions are just to show that I
did some homework.
#include <sstream>
#include <istream>
#include <string>
using namespace std;
int main(){
string f_name = "../myProg/str1/some_data_file" ;
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
}
*************** *************** *************** *************** ****
~/toy $ make clean; make
rm -rf *.o proj
g++ -gdwarf-2 -c -o my.o my.cpp
my.cpp: In function ¡Æint main()¡Ç:
my.cpp:9: error: variable ¡Æstd::ifstream ifs¡Ç has initializer but incomplete type
my.cpp:11: error: ¡Æcout¡Ç was not declared in this scope
my.cpp:13: error: ¡Æcout¡Ç was not declared in this scope
make: *** [my.o] Error 1
~/toy $
Gary Wessle wrote:
Gary Wessle <ph****@yahoo.c omwrites:
>"Victor Bazarov" <v.********@com Acast.netwrites :
>>Gary Wessle wrote: I have a code, the part which is troubling goes like this
************ *************** *************** *************** ******* #include <istream> #include <ostream> #include <fstream>
using std::ifstream; using std::ofstream; ... ifstream ifs(f_name.c_st r()); if( ifs.is_open() ) cout << "is open" << endl; else cout << "closed" << endl; ...
when run into the debugger "gdb" it shows "closed", however it prints "p f_name" fine and if I take that and copy it to the command line "cat /full/path/to/file" it prints out. the permission on that file is -rw-r--r--
"permission s" are OS-specific. "Debuggers" are tools and OS-specific. Please post OS-speficic inquiries to the newsgroup dedicated to that OS.
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
well, the code I posted will print "closed" where I expected it to print out "is open". the statements about the gdb and permissions are just to show that I did some homework.
#include <sstream>
#include <istream>
#include <string>
using namespace std;
int main(){
string f_name = "../myProg/str1/some_data_file" ;
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
}
*************** *************** *************** *************** ****
~/toy $ make clean; make
rm -rf *.o proj
g++ -gdwarf-2 -c -o my.o my.cpp
my.cpp: In function $B!F(Bint main()$B!G(B:
my.cpp:9: error: variable $B!F(Bstd::if stream ifs$B!G(B has initializer but
incomplete type my.cpp:11: error: $B!F(Bcout$B !G(B was not declared in this
scope
my.cpp:13: error: $B!F(Bcout$B !G(B was not declared in this scope
make: *** [my.o] Error 1
~/toy $
You need to include <fstream>, I am not sure what you need <istreamfor.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On 06 Feb 2007 03:02:43 +1100 in comp.lang.c++, Gary Wessle
<ph****@yahoo.c omwrote,
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
My suggestion (as usual) is
ifstream ifs(f_name.c_st r());
if(!ifs)
perror(f_name.c _str());
Gary Wessle wrote:
hi
I have a code, the part which is troubling goes like this
*************** *************** *************** *************** ****
#include <istream>
#include <ostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
...
ifstream ifs(f_name.c_st r());
if( ifs.is_open() )
cout << "is open" << endl;
else
cout << "closed" << endl;
...
when run into the debugger "gdb" it shows "closed", however it prints
"p f_name" fine and if I take that and copy it to the command line
"cat /full/path/to/file" it prints out. the permission on that file is
-rw-r--r--
Maybe the file is in use already and you can't open it to read?
HTH,
- J. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ram Laxman |
last post by:
Iam new bie to C++ programming..
I want to write a program which will read the Comma separated
values(CSV) file column wise.
For example:
In a.txt:
"TicketNumber","Phone","CarNumber"
10,20,30
|
by: hall |
last post by:
Hi.
I ran across a bug in one of my problems and after spending some time
tracking it down i found that the problem arose in a piece of code that
essentially did this:
-----------
ifstream in("in.txt"); if(!in) {cout << "error\n";}
in.close(); if(!in) {cout << "error\n";}
in.close(); if(!in) {cout << "error\n";}
|
by: sam |
last post by:
Hi,
Can anyone tell me how to print a file name from ifstream?
the following cout code does not print the filename I created with
ifstream preivous:
ifstream is;
is.open ("text.txt");
|
by: Earl Purple |
last post by:
This is a simple function to split a file into multiple files
(archives) of a fixed size. The last one will contain any remaining
bytes.
Here is the implementation:
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <vector>
|
by: Karl |
last post by:
Hey everyone!
I've got a quick question on whether std::ifstream is buffered or not.
The reason is that I have a homework assignment that requires me to
benchmark copying files using different buffer sizes. I ended up doing
this using std::istream::readsome() and std::ostream::write():
// now try writing to the destination file
std::ifstream sourceStream(sourceFilename.c_str(),
std::ios::binary);
| |
by: Paulo da Silva |
last post by:
How can I use a ifstream object to input from stdin?
Ex.
ifstream inf;
if (fn=="-")
{ what here to use inf as cin?
}
else
{ inf.open(fn.c_str,ios::in);
}
|
by: Pinux |
last post by:
Hi,
I now run into a very strange behavior when using ifstream. Can anyone please help me out here:
Basically, what I want to do is to encrypt a plain text file into a cipher text and then decrypt it back to the plain text file. I use ifstream to read the file into the buffer. Let's say the size of my encrypted file is 816 bytes. Normally after opening the file and calling the inf.read(garbage, 16), the get pointer should be moved from...
|
by: Xiaozhou.Yin |
last post by:
Hi~
In the program,I first used the ifstream variable fin open the file
and,open it again after called the fin.close().But the fin is fieled
to open the file in the second time.The book I'm learning hadn't
picked out this.Is it a common problem?Or just occurs in Vc++6.0?
#include<fstream>
#include<iostream>
using namespace std;
int count(ifstream& fin);
|
by: Johannes Bauer |
last post by:
Hello group,
coming from C, I'm used to somthing like this when opening a file
const char *foobar = "this.txt";
FILE *f;
f = fopen(foobar, "r");
if (!f) {
fprintf(stderr, "Couldn't open %s: %s\n", foobar, strerror(errno));
exit(EXIT_FAILURE);
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |