Visual C++ 2010 は、「式: 文字列の添字が範囲外です」と言い続けます。「inStringP.length()」の長さよりも長いループを実行していると考えたため、for ループの条件テストで整数から 1 または 2 を加算および減算しましたが、これは成功しません。グーグルは今日もいつもの天才的な自分を感じていません.....
#include <iostream>
#include <cstdlib>
#include <string>
#include "stdAfx.h"
using namespace std;
string removeChar(string inStringP){
string temp;
for(int i=0;i<inStringP.length()-1;i++){
if(inStringP[i]!='p'){
temp[i]=inStringP[i];
}
}
return temp;
}
int main(){
string sample = "Peter picks a peck of pickled peppers";
cout<<removeChar(sample)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}