LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2014, 05:59 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
c++ open ifstream has stopped working


Hi All,
this is driving me nuts and hope someone can point me in the right direction. I have some old very simple code that save and opens a file. It's worked for a very long time. I've now upgraded to lubuntu 14.04 (it may have done GCC as well I presume?) and all of a sudden it's stopped working. What I do is
Code:
ifstream myfile ("menu.txt");


if ( myfile.is_open( ) )
{
	while ( getline (myfile,line) )
	{
              prcocess stuff
         }
}
else
{
can't open error
}
Since the upgrade in Lubuntu I suddenly can't open. What I've tried
1. putting full path. Hasn't worked
2. chmod a+rwx on txt file, didn't work
3. tried a new text file helloworld.txt, didn't work.
4. tried as sudo, no luck

Should add I've upgraded my harddrive to SSD can this make a difference?

Can anyone advise why a simple open file as suddenly stopped working, or what I might try to get it to work?
Thanks

Last edited by knobby67; 11-15-2014 at 06:02 AM.
 
Old 11-15-2014, 07:10 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
Exactly what did you do, and exactly what error message did you get?

Note: normally you handle files like this:
Code:
FILE *f= fopen (name, mode);
if (!f) {
    fprintf (stderr, "Error opening file '%s' mode '%s' errno=%d: %s\n",
        name, mode, errno, strerror (errno));
    exit (12);
}
 
Old 11-15-2014, 10:22 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
It doesn't give an error it drops into the part of my code that handles no no file present. But it is, that's why I tried all the ways I did above. Also this has only started since I upgrade my OS from 13.4 to 14.04
 
Old 11-15-2014, 11:16 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
Should I suggest strace?
 
Old 11-15-2014, 11:36 AM   #5
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Thanks for the help, I got it to work with

Code:
ifstream myfile;
myfile.open("menu.txt");
rather than
Code:
ifstream myfile ("menu.txt");
I have no idea why this is working while the original will not.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
$ startx stopped working, was working fine when I shut it down last night BogoMIPS_1962 Slackware 2 08-10-2013 01:04 PM
[SOLVED] Ubuntu 11.04 mic stopped working in HP G-32, but was working before.how to fix it? Highjo Ubuntu 4 08-08-2011 05:59 AM
Three Mobile Broadband was configured and working but it has now stopped working and Tinabarma Linux - Newbie 0 10-20-2008 07:36 AM
X stopped working ... Rackerz Ubuntu 1 12-11-2005 08:09 PM
It stopped working. UmneyDurak Fedora 8 08-15-2004 02:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration