Visual with std :: transform中的错误C3861

时间:2012-04-01 12:52:44

标签: c++ transform

我有点好奇为什么我在Xcode上使用mac编写的程序运行良好,但是当我尝试使用visual studio编译windows系统时,

我收到以下错误:

  

c:\ users \ bryan \ documents \ visual studio   2010 \ projects \ new \ new \ new.cpp(172):错误C3861:'transform':   找不到标识符。

当我在程序中的任何地方编写转换时,实际上它表示相同的消息,就好像transform不是std命名空间的一部分。如果你想亲眼看看,这是我的代码:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cctype>
using namespace std;
string getInput ();
ifstream * openInFile ();
int getShiftValue ();
void cypherMenu ();
void menu ();
string shiftCharacters (int shiftNum, ifstream * inFile);
string getOutput ();
ofstream * openOutFile ();
void printSentence (string outData, ofstream * outFile);
void notOption (string optionString);
string capitalize (string choice);
string option ();
int main() {
ifstream * inFile;
ofstream * outFile;
string inFileName, outFileName, outData, optionString, capOptionString; 
int shiftNum = 0;
bool isOption = false; 
while (capOptionString.compare("2") != 0 || 
capOptionString.compare("QUIT") != 0) {
do {
    menu();
    optionString = option();
    capOptionString = capitalize(optionString);
    if (capOptionString.compare("1") == 0 || capOptionString.compare("CAESAR")
        == 0) {
        isOption = true;
    }
    else if (capOptionString.compare("2") == 0 || 
            capOptionString.compare("QUIT") == 0) {
            isOption = false;
    return 0;
    }
    else {
    notOption(optionString);
    }
}
while (!isOption);
cypherMenu();
inFile = openInFile(); 
shiftNum = getShiftValue();
outData = shiftCharacters(shiftNum, inFile);
inFile->clear();
inFile->close();
outFile = openOutFile();
printSentence(outData, outFile);
outFile->clear();
outFile->close();
}
return 0;
}
// Input Functions
string getInput () {
cout << "Enter an input file name: "; 
string inFileName;
getline(cin, inFileName); 
return inFileName;
}
string getOutput () {
string outFileName;
cout << "Enter an output file name: ";
getline(cin, outFileName);
cout << endl;
return outFileName;
}
ifstream * openInFile () {
ifstream * inFile; 
bool isGood = false; 
string inFileName; 
inFile = new ifstream;
do { 
    inFileName = getInput();
    inFile->open(inFileName.c_str());
    if (inFile->fail()) { 
    cout << "Couldn't open file" << endl;
    }
    else {
    isGood = true;
    }
}
while (!isGood);
return inFile;
}
ofstream * openOutFile () {
ifstream testStream; 
ofstream * outFile; 
bool isUnique = false; 
string fileName;
do { 
    fileName = getOutput();
    testStream.clear(); 
    testStream.open(fileName.c_str(), ios_base::in);
    if (testStream.good()) {
        cout << "The file already exists, please choose another" 
        << endl;
        testStream.clear();
        testStream.close();
    }
    else {
        isUnique = true;
        testStream.clear();
        testStream.close();
    }
}
while (!isUnique);
outFile = new ofstream;
outFile->open(fileName.c_str());
return outFile;
}
int getShiftValue () {
int shiftNum;
string trash;
cout << "Please enter shift value: ";
cin >> shiftNum;
getline(cin, trash); 
return shiftNum;
}
string option () {
string optionString;
getline(cin, optionString);
cout << endl;
return optionString;
}
// Data manipulation functions 
string shiftCharacters (int shiftNum, ifstream * inFile){
string inData, outData, trash, tempString; 
char outChar;
int idx = 0, idxTwo = 0, newLines = 0;
stringstream outSentence; 
do {
    while (getline(* inFile, inData, '\n')) {
        for (idx = 0; idx <= inData.length() - 1; idx++) {
            if (inData[idx] >= 'a' && inData[idx] <= 'z') {
            outChar = (((inData[idx] - 'a') + shiftNum) % 26) +
            'a';
            outSentence << outChar;
            }
            else if (inData[idx] >= 'A' && inData[idx] <= 'Z') {
                outChar = (((inData[idx] - 'A') + shiftNum) %  26) +
                'A';
                outSentence << outChar;
            }
            else {
                outChar = inData[idx];
                outSentence << outChar;
            }
        }
        outSentence << '\n';
        newLines++;
    }
}
while (!inFile->eof());
for (idxTwo = 0; idxTwo <= newLines + 1; idxTwo++) {
    getline(outSentence, tempString); 
    outData.append(tempString);
    outData += '\n';
}
return outData;
}
string capitalize (string choice) {
string outString;
outString.resize(choice.length());
transform(choice.begin(), choice.end(), outString.begin(), ::toupper);
return outString;
}
// Output funcitons
void cypherMenu () {
cout << "C A E S A R C Y P H E R P R O G R A M" << endl
<< "========================================" << endl;
return;
}
void printSentence (string outData, ofstream * outFile) {
int idx = 0;
char outChar;
stringstream outString;
outString << outData;
for (idx = 0; idx <= outData.length() - 1; idx++) { 
    outChar = outString.get();
    outFile->put(outChar); 
}
}
void menu () {
cout << "Available Options: " << endl 
    << "1. CAESAR - encrypt a file using Caesar Cypher" << endl
    << "2. QUIT - exit the program" << endl << endl
    << "Enter a keyword or option index: ";
return;
}
void notOption (string optionString) {
cout << optionString << " is an unrecognized option, try again" << endl 
<< endl;
return;
}

问题在于大写功能下的转换。它似乎根本不知道转换,我甚至试图在它之前编写std::,但它说没有名为transform的成员。我的编译器有问题,或者因为我下载了新的工作室后变换甚至已经使用了,或者这可能只是不好的做法?

1 个答案:

答案 0 :(得分:14)

正如您在阅读文档时所发现的那样(例如http://en.cppreference.com/w/cpp/algorithm/transform),std::transform在标准标题<algorithm>中定义,您不包括此标题。