帮忙看看模板类到底哪里出错了

qq459673705 2010-11-10 09:13:56
#include <string>
#include <iostream>

using namespace std;
template<typename T>
void rtrim(basic_string<T>& s,T c)
{
if(s.empty())
return;

typename basic_string<T>::iterator p;
for(p=s.end();p!=s.begin()&&*--p==c;);
if(*p!=c)
p++;
s.erase(p,s.end());
}
int main()
{
string s="Great!!!!!";
wstring ws=L"super!!!!";

rtrim(s,'!');
rtrim(ws,L"!");

cout<<s<<'\n';
wcout<<ws<<L'\n';
}
总是提示;

22.cpp:23: error: no matching function for call to ‘rtrim(std::wstring&, const wchar_t [2])’
实在找不到问题所在了,
谢谢!
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq459673705 2010-11-10
  • 打赏
  • 举报
回复
多谢了!1楼发帖早点,就按20,10,10给分吧!再次感谢!
GoonYangXiaofang 2010-11-10
  • 打赏
  • 举报
回复
char
wchar_t
無_1024 2010-11-10
  • 打赏
  • 举报
回复

#include <string>
#include <iostream>

using namespace std;
template<typename T>
void rtrim(basic_string<T>& s,T c)
{
if(s.empty())
return;
typename basic_string<T>::iterator p;
for(p=s.end();p!=s.begin()&&*--p==c;);
if(*p!=c)
p++;
s.erase(p,s.end());
}
int main()
{
string s="Great!!!!!";
wstring ws=L"super!!!!";
rtrim(s,'!');
rtrim(ws,L'!');//单引号就可以了
cout<<s<<'\n';
wcout<<ws<<L'\n';
return 0;
}

「已注销」 2010-11-10
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>

using namespace std;
template<typename T>
void rtrim(basic_string<T>& s, T c)
{
if (s.empty())
return;

typename basic_string<T>::iterator p;
for (p = s.end(); p != s.begin() && *--p == c;);
if (*p != c)
p++;
s.erase(p, s.end());
}
int main()
{
string s = "Great!!!!!";
wstring ws = L"super!!!!";

rtrim<char>(s, '!');
rtrim<wchar_t>(ws, L'!');

cout << s << '\n';
wcout << ws << L'\n';
}
Jim_King_2000 2010-11-10
  • 打赏
  • 举报
回复
rtrim(ws,L"!");
rtrim(ws,L'!');
用单引号。

65,207

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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