C语言反序输出英文句子,C++实现英文句子中的单词逆序输出的方法
本文實(shí)例講述了C++實(shí)現(xiàn)英文句子中的單詞逆序輸出的方法。分享給大家供大家參考,具體如下:
#include "stdafx.h"
#include
#include
#include
using namespace std;
int main(int arc,char** argv)
{
string str="I come from liaoning.";
stack works;
int len=str.length();
while(1)
{
int start=str.find_first_not_of(" ");
int end=str.find_first_of(" ");
int wlen=end-start;
if(end!=-1)
{
string temp=str.substr(start,wlen);
works.push(temp);
}
else
{
works.push(str);
break;
}
str=str.substr(end+1,len-wlen);
}
while(!works.empty())
{
string temp=works.top();
cout<
works.pop();
}
cout<
system("pause");
return 0;
}
運(yùn)行效果圖如下:
希望本文所述對(duì)大家C++程序設(shè)計(jì)有所幫助。
總結(jié)
如果覺(jué)得編程之家網(wǎng)站內(nèi)容還不錯(cuò),歡迎將編程之家網(wǎng)站推薦給程序員好友。
本圖文內(nèi)容來(lái)源于網(wǎng)友網(wǎng)絡(luò)收集整理提供,作為學(xué)習(xí)參考使用,版權(quán)屬于原作者。
小編個(gè)人微信號(hào) jb51ccc
喜歡與人分享編程技術(shù)與工作經(jīng)驗(yàn),歡迎加入編程之家官方交流群!
總結(jié)
以上是生活随笔為你收集整理的C语言反序输出英文句子,C++实现英文句子中的单词逆序输出的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 谁知道地下城与勇士的装备锻造怎么弄??
- 下一篇: c语言int 转bool_C++代码实现