在Unix/Linux(Ubuntu)中编译头文件和两个.cpp文件
Compile header file and two .cpp files in Unix/Linux (Ubuntu)
我试图编译总共3个文件,但无法编译。代码在visual++中工作。我已经上传了同一目录中的所有3个文件,并使用了以下命令。
g++-o编辑相册.cpp lab8.cpp
下面列出了我的文件名相册.cpp相册.hlab8.cpp
请注意,代码是在visual studio C++中编写的,在那里编译得很好。
导致以下
lab8.cpp:在函数"std::vector read_album_file(std::string)"中:lab8.cpp:142:25:错误:对"std::basic_ifstream::basic_ifstream(std::string&)"的调用没有匹配的函数ifstream读取(文件名);//ifstream用于从文件中读取^lab8.cpp:142:25:注意:候选者是:在lab8.cpp:38:0:/usr/include/c++/4.8/fstream:467:7:注意:std::basic_ifstream<_CharT,_Traits>::basic_ifstream(const char*,std::ios_base::openmode)[其中_CharT=char;_Traits=std::char_Traits;std::ios _base::openmode=std:basic_ifstream(const char*__s,ios_base::openmode __mode=ios_base::in)^/usr/include/c++/4.8/fstream:467:7:注意:参数1从"std::string{aka std::basic_string}"到"const char*"没有已知的转换/usr/include/c++/4.8/fstream:453:7:注意:std::basic_ifstream<_CharT,_Traits>::basic_ifstream()[其中_CharT=char;_Traits=std::char_Traits]basic_ifstream():__istream_type(),_M_filebuf()^/usr/include/c++/4.8/fstream:453:7:注意:候选者需要0个参数,提供1个/usr/include/c++/4.8/fstream:427:11:注意:std::basic_ifstream::basic_ifstream(const std::basic_ifstream&)class basic_ifstream:公共basic_stream<_CharT,_Traits>^/usr/include/c++/4.8/fstream:427:11:注意:参数1从"std::string{aka std::basic_string}"到"const std::basic_ifstream&"没有已知的转换
看看ifstream的构造函数原型。它需要一个const char *
和一个可选参数,因此您需要编写filename.c_str()
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 命名空间中具有.h和.cpp文件的类
- 为什么我的主文件.cpp不打印头文件中的任何内容
- 生成文件错误 - 找不到文件 - *.cpp
- 如何在文件.cpp gtkmm中声明小部件
- 没有实现文件(.cpp)的派生类
- 如何使用"CMakeLists.txt"中的add_library将整个文件(.cpp,.h等)包含在目录中
- 如何在Linux / Windows操作系统上使用文件*.cpp一步编译下面的代码
- 关于 Linux .so 文件无法链接到主文件.cpp文件
- 文件.cpp从Windows到Linux
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- 如何将文件.cpp编译为本机编译
- 使用模板类时,似乎无法包含除 main 以外的任何 cpp 文件.cpp
- 无法编译C++文件.cpp。C++98模式
- 为什么C++头文件不需要包含实现文件 (.cpp)
- 如何访问位于独立文件(.cpp)中的非成员函数
- 如何在Visual Studio Code中通过键盘快捷键切换头文件/cpp文件
- 如何将数据从stringstream写入文件(CPP)
- 为什么filestream不把空白写入文件cpp ?