J
jl_post
Hi,
I won't get into the details, but I discovered something strange
recently.
If I have the following C++ program:
#include <iostream>
#include <fstream>
int main(int argc, char ** argv)
{
std:
fstream someFile("/tmp/hello.txt");
someFile << "Hello!\n";
return 0;
}
and compile and run it, I get a file named "hello.txt" containing the
following line:
Hello!
But if I replace the first two lines of the main() function with this
one line:
std:
fstream("/tmp/hello.txt") << "Hello!\n";
the "hello.txt" file will contain a (non-newline terminted) line like:
0x44000f
It seems to me that the second approach is writing out the hexadecimal
address of the first character of the "Hello!\n" string to file.
But why? In both cases I'm creating a std:
stream object and
streaming a literal string to it.
Why would creating a std:
fstream variable and streaming to it (the
first approach) be any different than streaming directly to the return
object of a std:
fstream constructor (the second approach)? I mean,
in both cases a std:
stream object is being constructed, right? So
why are they doing something different with the stream operator?
Thanks for any input.
-- Jean-Luc
I won't get into the details, but I discovered something strange
recently.
If I have the following C++ program:
#include <iostream>
#include <fstream>
int main(int argc, char ** argv)
{
std:
someFile << "Hello!\n";
return 0;
}
and compile and run it, I get a file named "hello.txt" containing the
following line:
Hello!
But if I replace the first two lines of the main() function with this
one line:
std:
the "hello.txt" file will contain a (non-newline terminted) line like:
0x44000f
It seems to me that the second approach is writing out the hexadecimal
address of the first character of the "Hello!\n" string to file.
But why? In both cases I'm creating a std:
streaming a literal string to it.
Why would creating a std:
first approach) be any different than streaming directly to the return
object of a std:
in both cases a std:
why are they doing something different with the stream operator?
Thanks for any input.
-- Jean-Luc