This one is a head scratcher!
This little block of code works just fine on a Linux X86 Box with gcc7 compiler, but when I use the same program on an Linux ARM7 SBC with gcc9 this fails to check the logs.
1 2 3 4 5 6 7 8 9 10
// Check to see if log size has changed
ifstream in1("oldlog");
string unused;
while(getline(in1, unused)){
olog++;
}
ifstream in2("newlog");
while(getline(in2, unused)){
nlog++;
}
But,on the same SBC the below works in another program I wrote so ifstream DOES work:
My first thought was file permissions but I only use the SBC as root so I have permission. I'm at a total loss here and can see no reason unless it's a compiler issue but one would think the newer gcc9 version would be a done deal, any suggestions would be appreciated, Thanks, Tom
There is also no code to check that the files have been opened OK.
If you're just checking that the size of the files has changed - rather than it's content (which the code above doesn't do), then just compare the file sizes:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <fstream>
#include <iostream>
int main()
{
std::ifstream ifs("test.txt");
if (!ifs)
return (std::cout << "Cannot open the file\n"), 1;
ifs.seekg(0, std::ios_base::end);
std::cout << "File size is " << ifs.tellg() << '\n';
}
Thank You all for your help, I'll post more code tonight after work, please remember I'm still very noob, also this program is like 200 lines so I only posted the trouble area. I've used the 2 ints to compare file sizes, they increment as those while statements iterate.
I know it isn't working because I did some tests on both computers:
I got lots of messages on the x86, and nothing on the SBC. I really have to wonder if this is a compiler issue. I also understand there are undoubtedly better ways to do this and would love to revise it but that still leaves a mystery and since the purpose of these little projects is to gain fluency and knowledge it would be best to figure out the failure in case I see it again.
> I really have to wonder if this is a compiler issue.
It's almost never a compiler issue, when those compilers are used by millions of people every day.
I found it, I'm an idiot.
Another part of the program I inserted that function into changes the directory.
I had to copy both logs into three different directories and it came to life.
Man was I angry when that test program ran perfect.
> Another part of the program I inserted that function into changes the directory.
And if you'd put the error checking in when you started, or first asked, the problem was solved days ago.
Twice you tried to blame the compiler for a PICNIC problem.
I'm a novice developer, and did implement some error reporting to the best of my ability which ultimately led me to this epiphany.
At the time, I couldn't see the issue so the only differences were platform and compiler version and it seemed plausible there needed to be something added to the compile string.
In all, I'm glad I made this error, user seeplus taught me another way to achieve the goal, so after this all runs I have a new tool to use when I revise the code.
Thank you to everyone who took the time to read this thread, I always spend a couple of days trying to work stuff out on my own but it's a nice feeling to know guidance from good people is a post away if I can't figure something out.