C++ assignment - need help

the spec for the project (instructions, requirements, etc.) and also my code is in a file called decrypt.txt. It compiles for me in Visual Studio however the Autograder is telling me that it is not compiling and giving me the following error message:

Files submitted were:
NOTE: gradeout.txt was created by the autograder
decrypt.cpp
gradeout.txt
Tests of Proj 4
~~~~~~~~~~~~~~~
Test 1 -- compilation
Your code could not be compiled. The following
compilation errors were reported:
>> begin compilation errors ================================
g++ -g -c -o proj4.o decrypt.cpp
decrypt.cpp: In function ‘int main()’:
decrypt.cpp:20: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)’
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
make: *** [proj4.o] Error 1
>> end compilation errors ==================================
The following tests were failed as a result of
the compilation errors mentioned above:

It may have something to do with what the Autograde wants differently with my code, but I'm unsure how to change it.

Show us line 20 of decrypt.cpp

Actually, just show the code.
Last edited on


#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
   ifstream testFile;
   string encryptedFile, file, fileName;

   cout << "Please enter the name of the file:";
   cin >> fileName;

   string line;
   ifstream inputfile (fileName);

   // open file
   if (inputfile.is_open()){

       // while there are still lines in the file
       while (inputfile.good() ){
           // get the line, put into the variable "line"
           getline (inputfile, line);
           bool right = false;
           bool hasDirection = false;   
           bool hasShift = false;        
           int shift = 0;
           for (int i=0; i < line.length(); i++){

               char c = line.at(i);
               if(c ==' '){
                   continue;
               }
               if(c == '+'){
                   shift = 0;
                   right = false;
                   hasDirection = false;
                   hasShift = false;
               }
                else if(c == '<'){
                    right = false;
                    hasDirection = true;
               }
                else if(c == '>'){
                    right = true;
                    hasDirection = true;
               }
                //if between 0 and 9
                else if(hasDirection && c >= 48 && c <= 57){
                    if(shift > 0){
                        shift = shift*10 + c - 48; //more than one digit
                    }
                    else{
                       shift = c - 48;
                       hasShift = true;
                    }
               }
                else{
                    if(!hasDirection || !hasShift){
                        cout << "*** ERROR: No shift value as expected ***" << endl;
                        cout << "Special character: ";
                    if(!hasDirection)
                        cout << "+";
                    else if(right)
                        cout << ">";
                    else
                        cout << "<";
                        cout << " requires a numeric following it." << endl;
                        break;
                    }   
                else if((c >= 97 && c <= 122) || (c >= 65 && c <= 90)){
                    //if it's a char
                    if(c >= 97){
                        //if lowercase, make it upper
                        c -= 32;
                    }
                    char newchar = c + shift;
                    if(!right)
                       newchar = c - shift; //other way on ascii
                       newchar = newchar - 65;
                   
                    if(newchar < 0){ //overflow
                        newchar = newchar % 26;
                        newchar = 26 - newchar;
                    }
                    else{
                        newchar = newchar % 26;
                    }
                   newchar = newchar + 65;       
                   cout << newchar;
                    }
                //prints two end-of-line characters
                else if(c=='#'){
                   cout << endl << endl;                                            
                   break;
               }
               }
              }
           }
      inputfile.close();
   }
   else{
       cout << "*** ERROR: Error in opening file ***" << endl;
       cout << "You entered an invalid file name. Please try again." << endl;
ifstream inputfile (fileName);
The ifstream constructor takes a char*, not a string

You're missing at least a } and possibly more from the end of the code posted.
Topic archived. No new replies allowed.