LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What do these ifstream errors mean please? (https://www.linuxquestions.org/questions/programming-9/what-do-these-ifstream-errors-mean-please-361402/)

twirl 09-08-2005 08:47 AM

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

geeman2.0 09-08-2005 09:24 AM

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.

Matir 09-08-2005 09:27 AM

Also, in the future, please try to post relevant code, in [ code ] brackets. :)

addy86 09-08-2005 10:58 AM

Is it possible that you forget one '}', or am I missing something?
Two '{' in lines 53 and 58, but only one '}' in line 61.

geeman2.0 09-08-2005 01:01 PM

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.

twirl 09-08-2005 07:34 PM

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


All times are GMT -5. The time now is 03:46 AM.