<分区>
我已经看到了很多,但似乎没有一个与我的问题相对应。该程序在本地运行良好,但在需要运行的服务器上我遇到了错误。
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;
我知道使用命名空间标准;这是不好的做法,但我被告知要为该项目