📄 string_tester.cpp
字号:
// String Tester
// Demonstrates string objects
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word1 = "Game";
string word2("Over");
string word3(3, '!');
string phrase = word1 + " " + word2 + word3;
cout << "The phrase is: " << phrase << "\n\n";
cout << "The phrase has " << phrase.size() << " characters in it.\n\n";
cout << "The character at position 0 is: " << phrase[0] << "\n\n";
cout << "Changing the character at position 0.\n";
phrase[0] = 'L';
cout << "The phrase is now: " << phrase << "\n\n";
for (int i = 0; i < phrase.size(); ++i)
cout << "Character at position " << i << " is: " << phrase[i] << endl;
cout << "\nThe sequence 'Over' begins at location " << phrase.find("Over") << endl;
if (phrase.find("eggplant") == string::npos)
cout << "'eggplant' is not in the phrase.\n\n";
phrase.erase(4, 5);
cout << "The phrase is now: " << phrase << endl;
phrase.erase(4);
cout << "The phrase is now: " << phrase << endl;
phrase.erase();
cout << "The phrase is now: " << phrase << endl;
if (phrase.empty())
cout << "\nThe phrase is no more.\n";
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -