【发布时间】:2015-05-19 01:46:59
【问题描述】:
我正在尝试编写一个模拟刽子手游戏的程序。
#include <iostream>
#include <string>
#include "assn.h"
using namespace std;
int main(){
clearScreen();
cout << "Enter a word or phrase: ";
string phrase;
std::getline(std::cin, phrase);
cout << endl << "Your phrase: " << phrase << endl;
cout << endl;
}
目前我可以获取输入字符串并保留空格,但我想创建另一个字符串,其中所有字母都替换为连字符并保留空格。我已经尝试查找它,但无法找到它。
【问题讨论】:
-
C++ 有很多不错的algorithms in the standard library,例如一个replace values(或replace while copying)。