/**
*功能:使用while循环从标准输入(cin)中吧单词读入到string中。这是一个“无穷”
* while循环,可以使用break语句中断(和退出程序)。对于读入的单词用系列if语句吧
* 该单词“映射”为一个整数值,然后用该整数值作为一个switch语句的选择条件
* 的意义。同上判定那个单词是程序的结束标志,用文件输出啦测试程序
*时间:2014年8月15日08:22:17
*作者::cutter_point
*/
#include
#include
#include
#include
#include
using namespace std; //设计一个类,包括所有功能 class operatorText { public: // operatorText()=default; operatorText(string s=""):s(s){} //标准输入(cin)中吧单词读入到string中 void inWord(istream &is); //整数值作为一个switch语句的选择条件的意义 string theMeanOfInt(); //读入的单词用系列if语句吧该单词“映射”为一个整数值,只要在类内部行动就可以了 void wordToInt(); private: //存放一个单词 string s; //存放这个单词相应的整数 int is; }; //标准输入(cin)中吧单词读入到string中 void operatorText::inWord(istream &is) { //输入一个单词,保存到类中 cout<<"\n输入单词:"; string ps; is>>ps; this->s=ps; } /* 读入的单词用系列if语句吧该单词“映射”为一个整数值, void wordToInt(const string s, int &is); */ void operatorText::wordToInt() { if(s=="i" || s=="I") { is=5; } else if(s=="love" || s=="Love" || s=="LOVE") { is=5; } else if(s=="China") { is=5; } else { is=1; cout<<"\n单词"<
>panDuan; if(panDuan == 'i') { while(1) { //创建一个单词对象 operatorText ot("haha"); ot.inWord(cin); //输入单词 ot.wordToInt(); //输入单词的意义 cout<
|