Re: Black magic when using fopen!?
On Oct 2, 3:32 pm, "fdm" <f...@gk.com> wrote:
"AnonMail2...@gmail.com" <anonmail2...@gmail.com> wrote in message
news:69c2ed0d-8ed2-416d-9d41-1ff4b7c78762@o10g2000yqa.googlegroups.com...
On Oct 2, 5:39 pm, "fdm" <f...@gk.com> wrote:
In a function I call fopen:
template<class V, class Dt>
unsigned int LoadFile(std::string & path) {
std::cout << "path = " << path << std::endl;
FILE *fptr = fopen(path.c_str(), "rb");
if (fptr==NULL) {
std::cout << "file not found!" << path << std::endl;
}
...
...
}
When I run it I get this:
path = /home/fdm/test.h2
file not found!
fptr is NULL, meaning that it cannot find the file. I have double check=
ed
that the file exist in this location.
Now here comes the wierd part. If I manually set the SAME path in the
function like:
template<class V, class Dt>
unsigned int LoadFile(std::string & path) {
std::cout << "before = " << path << std::endl;
path = "/home/fdm/test.h2";
std::cout << "after = " << path << std::endl;
FILE *fptr = fopen(path.c_str(), "rb");
if (fptr==NULL) {
std::cout << "file not found!" << path << std::endl;
}
...
...
}
I get this:
before = /home/fdm/test.h2
after = /home/fdm/test.h2
and fptr is not NULL (the file is read successfully). But as can be see=
n
from the printed messages there is no difference between 'path' before =
and
after updating it! So why does it only work when I update 'path' manual=
ly
in
the function??
I get this error on Ubuntu 9.04. If I run it on windows vista 64 bit in
visual studio it works fine! Any ideas??
Perhaps there are trailing unprintable characters in the path string
passed to your function? Try printing the size of your string.
Good point and you are right:
Before:
pathB size = 78
After:
pathA size = 77
But how do I find out what the last char is? There is no trim function in
the stl but I have found:
[redacted]
But even if I pass my string to this function it still has size 78
afterwards! Any ideas?
Delimiters!!!!!!
std::cout << '"' << path << '"' << std::endl;