Thread: Why am I getting this error?

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    1

    Why am I getting this error?

    I am trying to create a simple string switch statement. Now, I know that you can use different variable types for the switch statement, but I keep getting an error that says "switch quanity is not an integer". Isnt it possible to have a "string" switch statement?

    Here is the switch:
    Code:
    string translate( string reg )
    {
        switch (reg)
        {
               case "$t0" :    return "01000";
               case "$t1" :    return "01001";
               case "$t2" :    return "01010";
               case "$t3" :    return "01011";
               case "$t4" :    return "01100";
               case "$t5" :    return "01101";
               case "$t6" :    return "01110";
               case "$t7" :    return "01111";
               case "$t8" :    return "10000";
               case "$t9" :    return "10001";
               case "$a0" :    return "00100";
               case "$a1" :    return "00101";
               case "$a2" :    return "00110";
               case "$a3" :    return "00111";
               case "$v0" :    return "00010";
               case "$v1" :    return "00011";
               default: return reg;
               
        }
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Nope.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Use a map instead.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    if statements are much simpler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM