Solved

use the switch...case!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
The dreaded error 1935 with VC++ 2008 Redistributable 12 88
C Language combined operators 28 106
mixing C++ & C# in Vis Studio 2013 7 141
Arduino EDI - Programming language 3 80
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now