| /************************************************************************** |
| * |
| * string.cpp - Example program of string. |
| * |
| * $Id: //stdlib/dev/examples/stdlib/manual/string.cpp#10 $ |
| * |
| *************************************************************************** |
| * |
| * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave |
| * Software division. Licensed under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance with the |
| * License. You may obtain a copy of the License at |
| * http://www.apache.org/licenses/LICENSE-2.0. Unless required by |
| * applicable law or agreed to in writing, software distributed under |
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| * CONDITIONS OF ANY KIND, either express or implied. See the License |
| * for the specific language governing permissions and limitations under |
| * the License. |
| * |
| **************************************************************************/ |
| |
| #include <iostream> // for cout, endl |
| #include <string> // for string |
| |
| #include <examples.h> |
| |
| |
| int main () |
| { |
| std::string test; |
| |
| // Type in a string over five characters long. |
| while (test.empty() || test.size() < 5) { |
| std::cout << "Type a string between 5 and 100 characters long. \n"; |
| std::cin >> test; |
| } |
| |
| // Try operator[] access. |
| std::cout << "Changing the third character from " |
| << test[2] << " to * \n"; |
| test [2] = '*'; |
| |
| std::cout << "now its: " << test << "\n\n"; |
| |
| // Try the insertion member function. |
| test.insert (test.size() / 2, "(the middle is here!)"); |
| std::cout << "Identifying the middle: " << test << "\n\n"; |
| |
| // Try replacement. |
| test.replace (test.find ("middle", 0), 6, "center"); |
| std::cout << "I didn't like the word 'middle', so instead, I'll say: \n" |
| << test << std::endl; |
| |
| return 0; |
| } |