只要注意一個點,for迴圈是要小於 .length()-2就可以了~
#include <iostream>
#include <iomanip>
using namespace std;
int
main ()
{
string a;
getline (cin, a);
for (int i = 0; i < a.length () - 2; i++)
{
a[i + 1] = '_';
}
for (int i = 0; i < a.length (); i++)
{
cout << a[i];
}
}