我是一個好日子的新手,我試圖輸入多個字符串,然後用字母「x」替換其中的幾個字符,以便在檢查時檢查它們他們顯示在屏幕上。我知道我的問題很簡單,但我很困難,需要一些幫助。我四處尋找這個答案,但沒有找到任何我可以使用的東西。這是我的代碼:嘗試替換C++字符串中的字符,完全卡住
#include<iostream>
#include<string>
using namespace std;
int main()
{
string name, userName, securityNumber, password;
string str1, str2, str3;
string x = "x";
cout << "Enter your name: ";
cin >> name;
cout << "Enter your Social Security Number: ";
cin >> securityNumber;
cout << "Enter your username: ";
cin >> userName;
cout << "Enter your password: ";
cin >> password;
{
securityNumber.replace(0, 99, x);
password.replace(0, 99, x);
str1 = name + " " + securityNumber;
str2 = userName + " " + password;
str3 = str1 + " " + str2;
}
cout << "Your information: " << str3 << endl;
system("Pause");
return 0;
}
你可以直接說'securityNumber = password = x;'然後。 – chris