字符串倒置輸出方法 C string怎么實現將字符串倒序儲存?
C string怎么實現將字符串倒序儲存?#Include<iostream>使用namespacesstdintmain(){chars[10]=“abcdefgh”char*P=&
C string怎么實現將字符串倒序儲存?
#Include<iostream>
使用namespacesstd
intmain()
{
chars[10]=“abcdefgh”
char*P=&s[strlen(s)-1],t
inti=0
//指針P指向字符串的最后一個字符。I是S的下標,從0開始。
]//使用中間變量交換開頭和結尾字符。
]while(P>=(S I))
{
]t=*P
]*P=S[I
]I
]P-->]}
]cout<<<endl
return0]}