473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Namespace clash for istream object :-(

Guys,

I have the following piece of code.

int myClass::myfn()
{
std::ifstream myFile;
myFile.open("/home/astvansh/devmap");
std::string line;
getline(myFile, line);
....
}

"devmap" is a text file. getline( ) returns an empty string on HP-UX,
but reads the text file successfully on Solaris and HP-UX. This code is
compiled using a proprietary STL library.

I wrote this program separately as test.cpp, built it using
"/opt/aCC/bin/aCC test.cpp", and it worked well on HP-UX. Hence, the
only difference is in the build environment.

I suspect the problem is because of _STL namespace. The object myfile
in my code is
of type _STL::basic_istream.

May someone please help me.

Thanks very much.

May 10 '06 #1
5 1682
vi************@gmail.com wrote:
Guys,

I have the following piece of code.

int myClass::myfn()
{
std::ifstream myFile;
myFile.open("/home/astvansh/devmap");
std::string line;
getline(myFile, line);
...
}

"devmap" is a text file. getline( ) returns an empty string on HP-UX,
but reads the text file successfully on Solaris and HP-UX. This code is
compiled using a proprietary STL library.

I wrote this program separately as test.cpp, built it using
"/opt/aCC/bin/aCC test.cpp", and it worked well on HP-UX. Hence, the
only difference is in the build environment.

I suspect the problem is because of _STL namespace. The object myfile
in my code is
of type _STL::basic_istream.


Are you sure the file is accessible? If iostreams were broken on my
compiler, I'd be afraid of my harddisk getting formatted next time I
compile something.

You could try posting in a newsgroup supporting your platform/compiler
to get more specific help.
Jonathan

May 10 '06 #2
Jonathan, thanks. I modified the code to:

int myClass::myfn()
{
std::ifstream myFile;
myFile.open("/home/astvansh/devmap");
if(!myFile)
{
std::cout << "Could not open file." << std::endl;
exit(-1);
}
std::string line;
getline(myFile, line);
if(line.empty())
{
std::cout << "Empty file." << std::endl;
}
....

}

The output is "Empty file." :-(

Thanks for the suggestion, Jonathan. I shall post the Q on HP-UX
forums, too.

May 10 '06 #3
vivek.astva...@gmail.com wrote:
Jonathan, thanks. I modified the code to:
Please quote the message you are answering to.
int myClass::myfn()
{
std::ifstream myFile;
myFile.open("/home/astvansh/devmap");
if(!myFile)
{
std::cout << "Could not open file." << std::endl;
exit(-1);
}
std::string line;
getline(myFile, line);
Try to qualify std::getline(), ADL may not be used if there's another
getline() somewhere.
if(line.empty())
{
std::cout << "Empty file." << std::endl;
}
...

}

The output is "Empty file." :-(


Is it empty? You know, try the easy stuff first, you may be suprised.
Did you try to use fopen() to see if the problem is with C++ iostreams
or if it's more general?
Jonathan

May 10 '06 #4
Thanks, Jonathan. Yes, I can read the file using fopen-fscanf. But the
iostream does not work :-(

May 10 '06 #5
Yeah, thanks Jonathan.

I promise I'll never forget to quote the problem I'm answering to.
May 10 '06 #6

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

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
10
by: Christian Christmann | last post by:
Hi, are there any drawbacks using "using namespace std" instead of defining the required namespaces like using std::cout
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
8
by: Marcin Kalicinski | last post by:
Is the code below ill formed (because operator >> is defined in different namespace than class B)? It fails with VS 2005 Beta. I don't know if I should redesign my code or if I should find a...
4
by: jalkadir | last post by:
This program does compile, but the linker says: main.o(.text+0x1a4):main.cpp: undefined reference to `jme::operator<<(std::ostream&, jme::Name const&)' here is the program's snips. ...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
4
by: anders | last post by:
I already asked this question in the VB.NET group but as C# seems to have the same problem, I'll try here, too. I have 2 external OEM assemblies A1 and A2 that both define class X (same name,...
2
by: Safalra | last post by:
The problem below is obviously some sort of namespace clash, but I don't understand exactly why - can anyone explain? Take the following simple Javascript code: <script type="text/javascript">...
3
by: Kourosh | last post by:
Hi all, I'm trying to call a COM function from C# The function gets a paramter of type IStream in C++. I've found the type System.Runtime.InteropServices.ComTypes.IStream, however I'm not sure...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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
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
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,...

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.