当前位置: 首页>>代码示例>>C++>>正文


C++ shared_ptr::toString方法代码示例

本文整理汇总了C++中tr1::shared_ptr::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::toString方法的具体用法?C++ shared_ptr::toString怎么用?C++ shared_ptr::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tr1::shared_ptr的用法示例。


在下文中一共展示了shared_ptr::toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {

  vector< tr1::shared_ptr<AbstractNumber> > ansHistory;
  vector<string>  expHistory;
  bool menuLoop = true;
    int input = 0;
    int setAns;
    cout << "||||   WELCOME   ||||" << endl;
    cout << "||||   TO OUR    ||||" << endl;
    cout << "|||| CALCULATOR  ||||" << endl;
    cout << " _____________________ " << endl;
    cout << "|  _________________  |" << endl;
    cout << "| |               0 | |" << endl;
    cout << "| |_________________| |" << endl;
    cout << "|  ___ ___ ___   ___  |" << endl;
    cout << "| | 7 | 8 | 9 | | + | |" << endl;
    cout << "| |___|___|___| |___| |" << endl;
    cout << "| | 4 | 5 | 6 | | - | |" << endl;
    cout << "| |___|___|___| |___| |" << endl;
    cout << "| | 1 | 2 | 3 | | x | |" << endl;
    cout << "| |___|___|___| |___| |" << endl;
    cout << "|_____________________|" << endl;

    while (menuLoop)
    {
    	cout << "\nPlease enter one of the options below: " << endl;
    	cout << "=================================================" << endl;
        cout << "1. Compute New Expression                       |" << endl;
        cout << "=================================================" << endl;
        cout << "2. Help                                         |" << endl;
        cout << "=================================================" << endl;
        cout << "3. Review Previous Expressions and Answers      |" << endl;
        cout << "=================================================" << endl;
        cout << "4. Quit                                         |" << endl;
        cout << "=================================================\n" << endl;

        cin>>input;

        if ( !( (1 <= input) && (input <= 4) ) )
        {
            cin.clear();
            while (cin.get() != '\n');
            cout << "\nNot a valid menu option. Please enter 1, 2, 3, or 4." << endl;
            continue;
        }

        switch (input)
        {
            case 1:
            {
                cin.ignore();
                bool keepCompute = true;
                while (keepCompute)
                {

                    string input2;
                    cout << "Enter the expression to compute. (Type 'back' to go back to the main menu)" << endl;
                    getline(cin, input2);
                    if(input2 != "")
                    {


                    	if (input2.find("back") != string::npos)
                    	{
                    		keepCompute = false;
                    	}
                    	else
                    	{

                    				try{
                    					if(input2.rfind("ans") != std::string::npos)
                    					{
                        				unsigned found = input2.rfind("ans");
                                        if (history == "")
                                            history = "0";
                    					input2.replace(found, std::string("ans").length(), "(" + history + ")");

                    					tr1::shared_ptr<AbstractNumber> num(new SumExpression(input2,true));
                    					historyAns = num->simplify();
                    					cout << "Result: \n" << historyAns->toString() << endl;
                    					ansHistory.push_back(historyAns);
                    					history = input2;
                    					expHistory.push_back(history);
                    					}
                    					else
                    					{
                    						tr1::shared_ptr<AbstractNumber> num(new SumExpression(input2,true));
                    						historyAns = num->simplify();
                    						cout << "Result: \n" << historyAns->toString() << endl;
                    						ansHistory.push_back(historyAns);
                    						history = input2;
                    						expHistory.push_back(history);
                    					}


                    				}
                    				catch(exception &msg)
                    				{

                    					cout << "***ERROR: "<< msg.what() << "***"  << endl;
//.........这里部分代码省略.........
开发者ID:kylelin47,项目名称:COP-Project,代码行数:101,代码来源:main.cpp


注:本文中的tr1::shared_ptr::toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。