反向打印字符串

STL的应用!

 

代码
#include <iostream>
#include
<string>
using namespace std;

int main()
{
const string delims(" \t,.;");
string line;
while (getline(cin, line))
{
size_t begIdx, endIdx;
begIdx
= line.find_first_not_of(delims);
while (begIdx != string::npos)
{
endIdx
= line.find_first_of(delims, begIdx);
if (endIdx == string::npos)
{
endIdx
= line.length();
}
for (int i = endIdx-1; i >= static_cast<int>(begIdx); --i)
{
cout
<< line[i];
}
cout
<< " ";
begIdx
= line.find_first_not_of(delims, endIdx);
}
cout
<< endl;
}
}

 

 

posted @ 2011-01-01 22:39  hailong  阅读(188)  评论(0编辑  收藏  举报