Solved

use the switch...case!

Posted on 2000-04-02
4
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

632 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