這是一個使用遞回法列印子序列和thei ascii值的程式
使用 命名空間 std.com.cn>。
void sub(string str,string ans)
{
if(str.length()==0)
{
cout<<ans<<endl。
return;
}
string ros=str.substr(1) 。
char ch=str[0] 。
sub(ros,ans)。
sub(ros,ans to_string(ch));/*here why is to_string function returning the ascii value of the character (in the place of to_string(ch) i was supposed to provide the ascii value*/)
sub(ros,ans ch)。
}
int main()
{
字串 str;
cout<<"輸入一個字串:"<<endl。
cin>>str。
sub(str,"") 。
return 0;
uj5u.com熱心網友回復:
為什么to_string函式回傳的是字符的ascii值
沒有
std::to_string(char),所以選擇了最匹配的函式,在這種情況下,它(很可能)是std::to_string(int)。std::to_string(int)只是列印出十進制的數字,就像使用printf("%d", value)。請看 https://en.cppreference.com/w/cpp/string/basic_string/to_string .轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/319301.html
標籤:
