Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
string.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <string> // for string
31
32#include <examples.h>
33
34
35int main ()
36{
37 std::string test;
38
39 // Type in a string over five characters long.
40 while (test.empty() || test.size() < 5) {
41 std::cout << "Type a string between 5 and 100 characters long. \n";
42 std::cin >> test;
43 }
44
45 // Try operator[] access.
46 std::cout << "Changing the third character from "
47 << test[2] << " to * \n";
48 test [2] = '*';
49
50 std::cout << "now its: " << test << "\n\n";
51
52 // Try the insertion member function.
53 test.insert (test.size() / 2, "(the middle is here!)");
54 std::cout << "Identifying the middle: " << test << "\n\n";
55
56 // Try replacement.
57 test.replace (test.find ("middle", 0), 6, "center");
58 std::cout << "I didn't like the word 'middle', so instead, I'll say: \n"
59 << test << std::endl;
60
61 return 0;
62}
int main()
Definition string.cpp:35