LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-08-2005, 08:47 AM   #1
twirl
Member
 
Registered: Aug 2005
Posts: 134

Rep: Reputation: 15
What do these ifstream errors mean please?


Hi,

i am trying to use ifstream to open a file a user specifys (Sourcode http://pastebin.com/357953). The problem is when i try and compile i get these errors :-

g++ gameserverpro11.cpp -o gameserverpro
gameserverpro11.cpp: In function `int main()':
gameserverpro11.cpp:67: error: jump to case label
gameserverpro11.cpp:57: error: crosses initialization of `std::ifstream in'
gameserverpro11.cpp:72: error: jump to case label
gameserverpro11.cpp:57: error: crosses initialization of `std::ifstream in'
gameserverpro11.cpp:76: error: jump to case label
gameserverpro11.cpp:57: error: crosses initialization of `std::ifstream in'
gameserverpro11.cpp:84: error: syntax error at end of input

any help would be much appreciated thankyou.

P.s you lot must be getting fed up of me asking by now lol
 
Old 09-08-2005, 09:24 AM   #2
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
That means you defined a new variable within one of your case statements.
The compiler doesn't like that, as some execution paths will skip the initialization of that variable.

Move the the variable declaration "ifstream in(filename)" on line 57 to a point above your switch statement, and then use in.open(filename) at line 57 instead to open your file.
 
Old 09-08-2005, 09:27 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
Also, in the future, please try to post relevant code, in [ code ] brackets.
 
Old 09-08-2005, 10:58 AM   #4
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Is it possible that you forget one '}', or am I missing something?
Two '{' in lines 53 and 58, but only one '}' in line 61.
 
Old 09-08-2005, 01:01 PM   #5
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
Code:
Is it possible that you forget one '}', or am I missing something?
Good eye!
It sure looks like he's missing a } somewhere, which probably caused the final error.
 
Old 09-08-2005, 07:34 PM   #6
twirl
Member
 
Registered: Aug 2005
Posts: 134

Original Poster
Rep: Reputation: 15
Hi,

yeah i noticed the missing stuff, its one of them things in c or c++ im sure everyone does it when they dont mean to like missing a ;:,"`' out. Since i cant do what i want with ifstream im going try use xtern and make an editor like nano/pico come up for the edit config file part.

Thankyou all for your help

twirl
 
  


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
(quick!) ifstream problem Liche Programming 1 10-04-2005 06:55 PM
Problems with ifstream/ofstream kornerr Programming 2 07-04-2005 11:31 AM
ifstream - Problem siemens Programming 2 05-13-2005 01:25 PM
ifstream errur ashirazi Programming 1 02-14-2005 04:35 AM
a class with a ifstream member Hano Programming 2 04-24-2002 11:01 AM

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

All times are GMT -5. The time now is 03:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration