123456789101112131415161718192021222324 |
- // forstr2.cpp -- reversing an array
- #include <iostream>
- #include <string>
- int main()
- {
- using namespace std;
- cout << "Enter a word: ";
- string word;
- cin >> word;
- // physically modify string object
- char temp;
- int i, j;
- for (j = 0, i = word.size() - 1; j < i; --i, ++j)
- { // start block
- temp = word[i];
- word[i] = word[j];
- word[j] = temp;
- } // end block
- cout << word << "\nDone\n";
- // cin.get();
- // cin.get();
- return 0;
- }
|