VisualStudio to DevC++ problem
Apr 21, 2014 at 11:49pm UTC
Hi guys.
So i have this homework i need to make in DevC++.
However, i normally just code in Visual Studio 2013 then copy+paste everything into DevC++. It worked for a few projects but honestly i knew i'll run into trouble one day.
I'm trying to make this function i made work with the DevC++ compiler.
It has 2 parameters, the first one is the name of the file that is going to be read and the second parameter is the name of the file that it's going to be written into.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//This is the function
void writeFromFile(string firstFile, string secondFile){
ifstream readFile;
readFile.open(firstFile);
ofstream writeFile;
writeFile.open(secondFile, ios::app);
writeFile << readFile.rdbuf() << endl;
readFile.close();
writeFile.close();
}
This function compiles fine in Visual Studio 2013, but in visual studio i have the following headers:
1 2 3 4 5
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string.h>
But when i try to compile in DevC++ i get a compiler error.
So i guess the problem is the header files or the syntax in DevC++ may be different for some of the classes used from fstream.
This is my compile log in DevC++:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Evidencia2.2\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Evidencia2.2\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp: In function `void writeFromFile(std::string, std::string)':
main.cpp:16: error: no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::open(std::string&, const std::_Ios_Openmode&)'
C:/Dev-Cpp/include/c++/3.4.2/fstream:695: note: candidates are: void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
make.exe: *** [main.o] Error 1
Execution terminated
I'd really appreciate some help, i can't find the problem after 3 hours :(.
Apr 22, 2014 at 12:08am UTC
Actually adding .c_str(), ios::in and .c_str(), ios::app solved this and managed to compile.
I feel dumb :(
Topic archived. No new replies allowed.