小编Uys*_*des的帖子

功能调用无法正常工作

这是我的函数调用,它有一个原型,一切都编译好,除了我没有得到我想要的结果.

string lower_case(string x)
{
    transform(x.begin(), x.end(), x.begin(), ::tolower);

    return x;
}
Run Code Online (Sandbox Code Playgroud)

现在这个简单的函数接受字符串并使其全部小写,我需要在我的代码中执行这么多次,所以不是一直重写这个,我想为它调用函数,但我没有得到它我想要的结果.例如,使用此代码:

int main()
{
 string str = "HELLO WORLD";
 lower_case(str);
cout<< str << endl;

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出仍然是HELLO WORLD而不是hello world,我是否正确地调用了该函数?

c++ string function-calls

0
推荐指数
1
解决办法
55
查看次数

g ++抱怨STD功能

我有一段下载的源代码,当尝试使用g ++编译器通过Cygwin进行编译时,编译器给出了一个错误,指出'transform'函数在此范围内未声明...

我正在使用std命名空间,我有正确的标头.我不确定它为什么不编译..语法看起来正确

这是代码块部分.

string tolower (const string & s)
  {
    string d = s;
    transform(d.begin(), d.end(), d.begin(), (int(*)(int)) tolower);
    return d;
  }  // end of tolower
Run Code Online (Sandbox Code Playgroud)

这是我的标题部分:

#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>

// standard library includes ...

#include <string>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <sstream>
#include <ios>
#include <iterator>

using namespace std; 
Run Code Online (Sandbox Code Playgroud)

c++ g++ std

-5
推荐指数
1
解决办法
74
查看次数

标签 统计

c++ ×2

function-calls ×1

g++ ×1

std ×1

string ×1