Thread: istringstream problem in switch block?

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    23

    Question istringstream problem in switch block?

    Dear all!
    I am using below switch block in a code. However it gives this compiler error;

    Main.cpp:85: error: jump to case label
    Main.cpp:81: error: crosses initialization of ‘std::istringstream iss1’

    it gives this error for iss2, iss3... too.

    What is the problem?

    Code:
     switch(argv[i][1])
           { 
             
           case 'f': i++;
    	 //sscanf(argv[i],"%d,%d",&n_start,&n_end); 
    	 istringstream iss1(argv[i]);
    	 iss1>> n_start >> n_end;                     
           break;
           
           case 'e': i++;
    	 //sscanf(argv[i],"%lf",&EPS);
             istringstream iss2(argv[i]);
             iss2>> EPS;
           break;
    
           case 't': i++;
    	 //sscanf(argv[i],"%lf",&ENT);
             istringstream iss3(argv[i]);
             iss3>> ENT;
           break;
    
           case 'i': i++;
    	 //sscanf(argv[i],"%lf",&dimg);
             istringstream iss4(argv[i]);
             iss4>> IMG;
           break;
    
           //default:
           //usage(); 
          }

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    If you create a variable in a switch statement, that switch statement must contain brackets.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    23
    could you write an example?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    switch(argv[i][1])
    { 
             
           case 'f':
           {
                     i++;
    	 //sscanf(argv[i],"%d,%d",&n_start,&n_end); 
    	 istringstream iss1(argv[i]);
    	 iss1>> n_start >> n_end;                     
           }
           break;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    23
    vart, Desolation, thanks so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch Problem
    By ahhak1989 in forum C Programming
    Replies: 35
    Last Post: 04-25-2009, 08:58 AM
  2. Switch function problem
    By Jack-Bauer in forum C++ Programming
    Replies: 6
    Last Post: 05-14-2006, 01:25 PM
  3. problem with an if statement block
    By DarkMortar in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 05:46 PM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  5. yeah alil help for my switch problem
    By datainjector in forum C Programming
    Replies: 7
    Last Post: 07-23-2002, 07:20 PM