< algorithm>的问题转变 [英] Problem with <algorithm> transform

查看:84
本文介绍了< algorithm>的问题转变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Kubuntu 64位系统c ++(GCC)4.0.3。


以下简单程序摘自p.497& 499 of N.M.Josurris''

" The C ++ Standard Library ... (文件t.cpp):


1 #include< string>

2 #include< iostream>

3 #include< algorithm>

4 #include< cctype>

5使用命名空间std;

6 int main(){

7字符串s(这是Hodna 1223的邮政编码);

8 cout<< original: << s<< endl;

9变换(s.begin(),s.end(),s.begin(),toupper);

10 cout< ;< upper: << s<< endl;

11}


执行''c ++ t.cpp'时导致以下错误输出


t.cpp:在函数a ?? int main()a ??:

t.cpp:9:错误:没有匹配函数用于调用

到a ?? 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>)a ??


似乎有些严重错误,但我无法理解。


帮助,建议非常感谢。

解决方案

transform(s.begin(),s.end(),s.begin(),toupper);


似乎有些严重错误,但我无法理解。



唉,toupper是一个宏,所以你不能把它作为一个参数传递。


On 2008-01-06 21:45,Andrew Koenig写道:


> transform(s.begin(),s.end(),s.begin(),toupper);


>似乎有些严重错误,但我无法理解。



唉,toupper是一个宏,所以你不能把它作为一个论点。



你确定吗?在C99中,它是一个指定为int toupper(int c)的函数

(第7.4.2.2节,toupper函数)和在C ++ 98表45中它是

也作为一个函数列出。


到OP:您发布的代码编译并运行良好的MSVC ++所以我是

不知道为什么它不适合你。然而,在< localeheader中声明的C ++中也有一个toupper()

函数可能有效(即

替换< cctypewith< locale并重试)。


-

Erik Wikstr ?? m


文章< lfagj.804

Working on a Kubuntu 64bit system "c++ (GCC) 4.0.3".

The following simple program extracted from p.497 & 499 of N.M.Josurris''
"The C++ Standard Library ... " (file t.cpp):

1 #include <string>
2 #include <iostream>
3 #include <algorithm>
4 #include <cctype>
5 using namespace std;
6 int main() {
7 string s("This is the zip code of Hodna 1223");
8 cout << "original: " << s <<endl;
9 transform(s.begin(), s.end(),s.begin(), toupper);
10 cout << "upper: " << s << endl;
11 }

results in the following error output when executing ''c++ t.cpp''

t.cpp: In function a??int main()a??:
t.cpp:9: error: no matching function for call
to a??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>)a??

Something seems seriously wrong but I can''t figure it.

Help, suggestions greatly appreciated.

解决方案

transform(s.begin(), s.end(),s.begin(), toupper);

Something seems seriously wrong but I can''t figure it.

Alas, toupper is a macro so you can''t pass it as an argument.


On 2008-01-06 21:45, Andrew Koenig wrote:

> transform(s.begin(), s.end(),s.begin(), toupper);

>Something seems seriously wrong but I can''t figure it.


Alas, toupper is a macro so you can''t pass it as an argument.

Are you sure? In C99 it is a function specified as int toupper(int c)
(section 7.4.2.2, "The toupper function") and in C++98 table 45 it is
also listed as a function.

To the OP: the code you posted compiled and ran fine with MSVC++ so I am
not sure why it did not work for you. However there is also a toupper()
function in C++ declared in the <localeheader which might work (i.e.
replace <cctypewith <localeand try again).

--
Erik Wikstr??m


In article <lfagj.804


这篇关于&lt; algorithm&gt;的问题转变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆