请哪位大虾的讲一下stl字符串类中各成员函数的功能?

tianyxy 2004-03-09 02:05:57
请哪位大虾的讲一下stl字符串类中各成员函数的功能?或者告知那里可以查到相关的资料 多谢了!
...全文
53 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2004-03-17
  • 打赏
  • 举报
回复
MSDN 2003 里面说得很全面;其它的资料也不会少。
softice2002 2004-03-17
  • 打赏
  • 举报
回复
下面的代码我中午休息的时候调试通过,也许对你有些帮助。

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;


std::string FindParam(std::string params,int n)
{
char a[20];
std::string token1=std::string(itoa(n,a,10))+",";
std::string token2=std::string(itoa(n,a,10))+"@";
std::string token3=",";

string::size_type begIdx, endIdx;

endIdx = params.find(token1);
if(endIdx != string::npos)
{
begIdx = params.rfind(token3,endIdx);
return params.substr(begIdx+1,endIdx-begIdx);
}

endIdx = params.find(token2);
if(endIdx != string::npos)
{
begIdx = params.rfind(token3,endIdx);
return params.substr(begIdx+1,endIdx-begIdx);
}

return "";

}


int main(int argc, char* argv[])
{
std::string params;
while(getline(cin,params))
{
std::string param = FindParam(params,3);
cout<<param<<endl;
}
}
softice2002 2004-03-17
  • 打赏
  • 举报
回复
int main (int argc, char** argv)
{
const string delims(" \t,.;");
string line;

// for every line read successfully
while (getline(cin,line)) {
string::size_type begIdx, endIdx;

// search beginning of the first word
begIdx = line.find_first_not_of(delims);

// while beginning of a word found
while (begIdx != string::npos) {
// search end of the actual word
endIdx = line.find_first_of (delims, begIdx);
if (endIdx == string::npos) {
// end of word is end of line
endIdx = line.length();
}

// print characters in reverse order
for (int i=endIdx-1; i>=static_cast<int>(begIdx); --i) {
cout << line[i];
}
cout << ' ';

// search beginning of the next word
begIdx = line.find_first_not_of (delims, endIdx);
}
cout << endl;
}
}
参考以上代码,应该可以搞定

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧