2012-04-01 10 views
0

Ich bin ein wenig neugierig, warum das Programm, das ich auf Xcode mit einem Mac schrieb fein läuft, aber wenn ich versuche, auf einem Windows-System mit Visual Studio kompilieren,Fehler C3861 in Visual mit std :: transformieren

Ich erhalte folgende Fehler:

c:\users\bryan\documents\visual studio 2010\projects\new\new\new.cpp(172): error C3861: 'transform': identifier not found.

als ich im Programm umwandeln überall schreiben, in der Tat, sagt es die gleiche Botschaft, wie transformieren, wenn nicht ein Teil des std-Namespace ist. Hier ist mein Code, wenn Sie für sich selbst sehen möchten:

#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; 
} 

Das Problem der unter dem funciton Kapital zu verwandeln ist. Es scheint überhaupt nicht zu transformieren, ich habe sogar versucht, std:: davor zu schreiben, aber es hieß, dass es kein Element namens transform gibt. Gibt es ein Problem mit meinem Compiler, oder wird die Transformation sogar noch verwendet, seit ich das neue Studio heruntergeladen habe, oder ist es vielleicht nur eine schlechte Übung?

+3

'#include ' '? – Mat

Antwort

13

Wie Sie aus dem Lesen der Dokumentation erfahren würden (z. B. http://en.cppreference.com/w/cpp/algorithm/transform), ist std::transform in der Standardkopfzeile <algorithm> definiert, die Sie nicht einschließen.

+0

oh haha ​​wow dummer Fehler. Vielen Dank! –