-2

こんにちは、たとえば、ある点から別の点に文字を印刷したい

string str = "what is o and o this "; //I want to print all the 
                        //characters [ O and O ]
string temp1;
int loc1, loc2;
loc1 = str.find_first_not_of('o');
loc2 = str.find_last_not_of('o');
temp1 = str.substr(loc1, loc2);
cout << temp1 << endl; //this prints out entire string

誰でも私を助けることができますか?? すべての助けをありがとう!!

4

1 に答える 1

2

関数と、位置ではなく長さを期待するfind_first_of/find_last_of2 番目のパラメーターを使用する必要があります。substr

string str = "what is o and o this "; //I want to print all the 
                        //characters [ O and O ]
string temp1;
int loc1, loc2;
loc1 = str.find_first_of('o');
if( loc1 == string::npos ) return; // symbol not found
loc2 = str.find_last_of('o');
temp1 = str.substr( loc1, loc2 - loc1 + 1 );
cout << temp1 << endl; //this prints out entire string
于 2013-11-13T21:09:51.000 に答える