Solved

use the switch...case!

Posted on 2000-04-02
4
208 Views
Last Modified: 2010-04-02
i want to put the string expession in
switch case,how can i do?
like:
string aaa;
switch (aaa)
case 'tse'
.................
i try to write like these.
but i can't.
thanks for your help!
0
Comment
Question by:erichuang
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
freshmeat earned 50 total points
ID: 2679141
try:
string aaa;
switch (aaa)
case "tse":
  //what u want to do;
  break;
case "xxx":
  //do what u want to do;
  break;
.....
default:
  //do your defaul action;

ha, ur name seems a Chinese
^@^
so am i!

 


0
 
LVL 2

Expert Comment

by:freshmeat
ID: 2679145
sorry, missed something in last post
try:
string aaa;
switch (aaa)
{
case "tse":
  //what u want to do;
  break;
case "xxx":
  //do what u want to do;
  break;
.....
default:
  //do your defaul action;
}


ha, ur name seems a Chinese
^@^
so am i!

 


0
 
LVL 1

Expert Comment

by:mahno
ID: 2679151
Hi erichuang,

This is impossible in switch...case construction. U can use if..else if

if (strcmp(str, "string1") == 0) {
//...
} else if (strcmp(str, "string2") == 0) {
//...
} else if (strcmp(str, "string3") == 0) {
//...
}

Hope that helps,
  mahno
0
 

Author Comment

by:erichuang
ID: 2679401
hi mahno,freshmeat:
    thank you for your help !
    althougeh i find another to solve this code. but i still very thanks for your provider.yes i am a chinese.

Have a nice DAY.
         YOUR FRIEND ERIC  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now