请问各位高手,transform函数的用法?

林子xxx 2008-03-18 01:27:13
小弟看书中有:transform(cingg.begin(),cingg.end(),cingg.begin(),toupper) 但不明白怎样用,请各位高手不吝赐教。
还有这是什么意思:no matching function for call to `transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
...全文
487 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
林子xxx 2008-03-18
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 coding_hello 的回复:]
英文不懂就找本中文的STL看看。做开发,完全不看英文文档怎么成,MSDN都是英文的
[/Quote]
决定学习好英语!
野男孩 2008-03-18
  • 打赏
  • 举报
回复
英文不懂就找本中文的STL看看。做开发,完全不看英文文档怎么成,MSDN都是英文的
luckyTheOne 2008-03-18
  • 打赏
  • 举报
回复
很容易明白,你的第四个参数toupper是一个操作符函数,你没有定义过,所以出错.
在这个函数前加上


char toupper(char lower)
{
return lower-36;
}


定义即可
如有不对,请指教
HelloDan 2008-03-18
  • 打赏
  • 举报
回复
里面有例子的,从例子推也可以自己推出来了啊。
iambic 2008-03-18
  • 打赏
  • 举报
回复
很讨厌的东西。
iambic 2008-03-18
  • 打赏
  • 举报
回复
恭喜楼主。你遇到这个错误是因为你现在有两个toupper。
你可以试下:
void(*u)() = toupper;

看编译器的错误提示就知道了。
试下:
transform(str.begin(), str.end(), str.begin(), (int(*)(int))toupper);
transform(str.begin(), str.end(), str.begin(), ::toupper);

林子xxx 2008-03-18
  • 打赏
  • 举报
回复
英文看不懂
林子xxx 2008-03-18
  • 打赏
  • 举报
回复
英文看不懂
林子xxx 2008-03-18
  • 打赏
  • 举报
回复
英文看不懂
HelloDan 2008-03-18
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/en-us/library/391xya49(VS.80).aspx
HelloDan 2008-03-18
  • 打赏
  • 举报
回复
http://www.cplusplus.com/reference/algorithm/transform.html
STL,参看这里吧。
林子xxx 2008-03-18
  • 打赏
  • 举报
回复
// transform algorithm example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int op_increase (int i) { return ++i; }
int op_sum (int i, int j) { return i+j; }

int main ()
{
vector<int> first;
vector<int> second;
vector<int>::iterator it;

// set some values:
for (int i=1; i<6; i++) first.push_back (i*10); // first: 10 20 30 40 50

second.resize(first.size()); // allocate space
transform (first.begin(), first.end(), second.begin(), op_increase);
// second: 11 21 31 41 51

transform (first.begin(), first.end(), second.begin(), first.begin(), op_sum);
// first: 21 41 61 81 101

cout << "first contains:";
for (it=first.begin(); it!=first.end(); ++it)
cout << " " << *it;

cout << endl;
return 0;
}

出错信息:
multiple definition of `main'
first defined here
D:\C++\trans\Makefile.win [Build Error] [Project1.exe] Error 1
编译器是Dev-c++

64,654

社区成员

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

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