Solved

use the switch...case!

Posted on 2000-04-02
4
211 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

840 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