我在 Visual Studio 2012 中编写了一个类程序,我想在 Linux 机器上运行它。我试过在 Linux 机器上编译,但我相信我使用的一些库不是跨平台兼容的。无论如何我可以创建一个可以在 Linux 上运行的 .o 文件,而不需要我更改我的代码?
语言:C++ 以下是我使用的库:
#include <iostream>
#include <queue>
#include <map>
#include <climits>
#include <iterator>
#include <algorithm>
#include <fstream>
#include <string>
#include <iomanip>
当我尝试在 Linux 中编译时会发生什么
Main.cpp: In function ‘int main()’:
Main.cpp:110:24: error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::string&)’
Main.cpp:110:24: note: candidates are:
/usr/include/c++/4.6/fstream:460:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
/usr/include/c++/4.6/fstream:460:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
/usr/include/c++/4.6/fstream:446:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.6/fstream:446:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.6/fstream:420:11: note: std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)
/usr/include/c++/4.6/fstream:420:11: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const std::basic_ifstream<char>&’