I have developed an application that needs to read some data from file, but it seems to not work, here is my code:
//this file exists, so no problem :/tmp/grab/applicationIconPath.txt
//i tried //tmp//grab//applicationIconPath.txt also but nothing changed
//the next line outputs nothing
std::cout << fileName << std::endl;
fullPath = "/usr/share/app-info/icons/archlinux-arch-extra/128x128/" + fileName;
//the next line outputs /usr/share/app-info/icons/archlinux-arch-extra/128x128/ only
std::cout << fullPath;
Last edited on
From your comments, it appears you are saying that it reaches lines 11 to 20, but outputs a blank line on line 15? Is this correct?
If so, it means you are successfully opening the file, but the getline call puts an empty string into fileName.
An additional check would be to wrap a check around the getline call:
if (!getline(applicationIconPath, fileName))
std::cout << "Error reading applicationIconPath\n";
Note that you are calling rm on the file after you run it, so unless you are re-creating the file each time, you will get different behavior the second time you run your program.
Are you positive that the very first line of your file contains text?
Also, "/" is correct. "//" would not be. So you're good there.
Last edited on
Thanks for responding,
I made a mistake, when the image that i look for doesn't exist in :/usr/share/app-info/icons/archlinux-arch-extra/128x128/
The program writes nothing to that file, and thus it won't work in the code i posted, i am figuring out right now how to solve it.
Thank you and have a nice day.
if you want to open something only if it exists, there is a nocreate flag you can try. ios::nocreate I think.