I compiled my program and when I upload it to be marked with fitch fork I get a few errors. The program compiles and runs when I run it outside fitch fork, I think the main problem is that my make file is not calling c++11 libraries.
Error Message:
make_clean 2
rm: cannot remove '*.o': No such file or directory rm: cannot remove 'main': No such file or directory make: *** [makefile:14: clean] Error 1
make 2
combiner.cpp: In member function 'void combiner::combineFragments(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)': combiner.cpp:75:16: error: no matching function for call to 'std::basic_ifstream::open(std::__cxx11::string&)' File1.open(f1); ^ In file included from combiner.cpp:5:0: /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: candidate: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits; std::ios_base::openmode = std::_Ios_Openmode] open(const char* __s, ios_base::openmode __mode = ios_base::in) ^ /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: no known conversion for argument 1 from 'std::__cxx11::string {aka std::__cxx11::basic_string}' to 'const char*' combiner.cpp:76:16: error: no matching function for call to 'std::basic_ifstream::open(std::__cxx11::string&)' File2.open(f2); ^ In file included from combiner.cpp:5:0: /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: candidate: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits; std::ios_base::openmode = std::_Ios_Openmode] open(const char* __s, ios_base::openmode __mode = ios_base::in) ^ /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: no known conversion for argument 1 from 'std::__cxx11::string {aka std::__cxx11::basic_string}' to 'const char*' combiner.cpp:77:16: error: no matching function for call to 'std::basic_ifstream::open(std::__cxx11::string&)' File3.open(f3); ^ In file included from combiner.cpp:5:0: /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: candidate: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits; std::ios_base::openmode = std::_Ios_Openmode] open(const char* __s, ios_base::openmode __mode = ios_base::in) ^ /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/fstream:595:7: note: no known conversion for argument 1 from 'std::__cxx11::string {aka std::__cxx11::basic_string}' to 'const char*' combiner.cpp:84:20: error: 'stoi' was not declared in this scope num = stoi(stemp); ^ combiner.cpp:103:20: error: 'stoi' was not declared in this scope num = stoi(stemp); ^ combiner.cpp:121:20: error: 'stoi' was not declared in this scope num = stoi(stemp); ^ make: *** [makefile:5: combiner.o] Error 1
make_run1 2
make: ./main: Command not found make: *** [makefile:11: run] Error 127
Code:
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
using namespace std;
#include "combiner.h"
void combiner::setRows(int a)
{
rows = a;
}
void combiner::setCols(int a)
{
cols = a;
}
int combiner::getRows()
{
return rows;
}
int combiner::getCols()
{
return cols;
}
void combiner::initialiseMap()
{
int rows = getRows();
int cols = getCols();
colourMap = new int * [rows];
for(int i = 0; i < rows; i++)
{
colourMap[i] = new int[cols];
}
for(int j = 0; j < rows; j++)
{
for(int l = 0; l < cols; l++)
{
colourMap[j][l] = -1;
}
}
}
void combiner::displayMap()
{
for(int j = 0; j < rows; j++)
{
for(int l = 0; l < cols; l++)
{
cout << colourMap[j][l];
if(l < cols-1)
{
cout << ",";
}
}
cout << endl;
}
}
void combiner::combineFragments(string f1, string f2, string f3)
{
int num, pos, lenght, cols = getCols()-1;
string temp, stemp;
ifstream File1, File2, File3;
File1.open(f1);
File2.open(f2);
File3.open(f3);
while(File1 >> temp)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-pos);
num = stoi(stemp);
colourMap[0][0] = num;
for(int i = 0; i < cols; i++)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-num);
num = stoi(stemp);
colourMap[i+1][0] = num;
}
}
while(File2 >> temp)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-pos);
num = stoi(stemp);
colourMap[0][1] = num;
for(int i = 0; i < cols; i++)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-num);
num = stoi(stemp);
colourMap[i+1][1] = num;
}
}
while(File3 >> temp)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-pos);
num = stoi(stemp);
colourMap[0][2] = num;
for(int i = 0; i < cols; i++)
{
pos = temp.find(",");
stemp = temp.substr(0, pos);
temp = temp.substr(pos+1, temp.length()-num);
num = stoi(stemp);
colourMap[i+1][2] = num;
}
}
File1.close();
File2.close();
File3.close();
}
void combiner::smoothColours()
{
int rows, cols, sum = 0, avg;
rows = getRows();
cols = getCols();
avg = rows*cols;
for(int j = 0; j < rows; j++)
{
for(int l = 0; l < cols; l++)
{
sum = colourMap[j][l] + sum;
}
}
avg = sum/(rows*cols);
for(int j = 0; j < rows; j++)
{
for(int l = 0; l < cols; l++)
{
colourMap[j][l] = avg;
}
}
}
makefile:
combiner: combiner main.cpp
g++ -c main.cpp combiner.cpp
g++ -std=c++11 -o main main.o combiner.o
main: main.cpp combiner.o
g++ -o main.a main.o
run:
./main
clean:
rm *.o main
Aucun commentaire:
Enregistrer un commentaire