Solved

use the switch...case!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 138
Grammars for C C++ and java 1 147
Eclipse IDE - Cannot copy/paste from console output 8 395
passing data from one form to another form in c++ 27 104
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

710 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