reverse.cpp

来自「在纯DOS下运行的TurboC3_ucos2_ucgui bug改进版本」· C++ 代码 · 共 47 行

CPP
47
字号
#if !defined( __STACK_H )
#include <Stack.h>
#endif	// __STACK_H

#if !defined( __STRNG_H )
#include <Strng.h>
#endif	// __STRNG_H

#ifndef __IOSTREAM_H
#include <iostream.h>       
#endif

int main()
{
    Stack theStack;
    String reverse("reverse");

    cout << "\nEnter some strings.  Reverse will collect the strings\n";
    cout << "for you until you enter the string \"reverse\".  Reverse\n";
    cout << "will then print out the strings you have entered, but in\n";
    cout << "reverse order.  Begin entering strings now.\n";

    for(;;)
        {
        char inputString[255];
        cin >> inputString;
        String& newString = *( new String( inputString ) );
        if( newString != reverse )
            {
            theStack.push( newString );
            }
        else 
            {
            break;
            }
        }

    cout << "\nThe strings you entered (if any) are:\n";
    while( !(theStack.isEmpty()) )
        {
        Object& oldString = theStack.pop();
        cout << oldString << "\n";
        delete &oldString;
        }
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?