未在范围内声明的 C++ 转换仅发生在服务器上

标签 c++ linux

<分区>

我已经看到了很多,但似乎没有一个与我的问题相对应。该程序在本地运行良好,但在需要运行的服务器上我遇到了错误。

project1.cpp:在函数‘void insertwords(char*)’中: project1.cpp:54:65: 错误:未在此范围内声明“转换” 转换(word.begin(),word.end(),word.begin(),::tolower);

相关代码:

void insertwords(char *filename) {
    ifstream fin;
    fin.open(filename);
        if(fin.fail())
            {
            cerr << "File opening failed. Exiting program.\n";
            exit (-1);
            }
    string word;
    int count = 0;
    while (!fin.eof() ) {
        word.clear();
        fin >> word;
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        for (int i = 0, len = word.size(); i < len; i++)
        {
            if(ispunct(word[i]))
            word.erase(i--, 1);
            len = word.size();
        }
        if(!word.empty()) {
            insert_word(word);
            ++count;
                }
        }


    cout << "The number of words found in the file was " << count << "\n";
    fin.close();
}

包括:

#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
#include <locale>

using namespace std;

我知道使用命名空间标准;这是不好的做法,但我被告知要为该项目

最佳答案

您需要 #include <algorithm>这是 std::transform 所在的标题来自。

至于为什么它会在一台机器上而不是另一台机器上编译,我的猜测是您的其他 header 之一(例如 <string> )包含 <algorithm>在其中一个编译器实现中,所以你很幸运,但对于另一个编译器则不然。

关于未在范围内声明的 C++ 转换仅发生在服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32408521/

相关文章:

具有奇数(非偶数)大小的 Linux block 设备

java - -XX :HeapDumpPath option in jvm config not working

c - 如何在 Linux 中获取键盘状态?

linux - 在不修改应用程序的情况下将数据包重定向到用户空间 TCP 堆栈

c++ - 将数据传递到字符串时如何保留文件的格式?

java - Android Studio - 在现有的旧项目中启用 native C++ 调试 (card.io Android Source)

c++ - 查找 map 中的最大值

java - 无法从 Java 为 Latex 运行终端命令

c++ "error: no matching function for call to"在集合中计数时

c++ - 可以创建 N 个方法的类接口(interface)