【发布时间】:2017-11-07 09:46:47
【问题描述】:
我想将整个文件读入一个字符串。我正在使用 Embarcadero C++Builder XE。
当我在我的项目中使用下面的代码时,它给出了错误:
#include <iostream>
#include <iomanip>
#include <iterator>
#include <fstream>
std::ifstream in(Path);
std::string s((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
[ILINK32 错误] 错误:未解析的外部 'std::_Mutex::_Lock()'
[ILINK32 错误] 错误:未解析的外部 'std::_Mutex::_Unlock()'
[ILINK32 错误] 错误:未解析的外部 'std::char_traits::eq_int_type(const int&, const int&)'
[ILINK32 错误] 错误:未解析的外部 'std::char_traits::not_eof(const int&)'
[ILINK32 错误] 错误:未解析的外部 'std::char_traits::to_char_type(const int&)'
[ILINK32 错误] 错误:未解析的外部 'std::char_traits::eof()'
[ILINK32 错误] 错误:未解析的外部 'std::char_traits::to_int_type(const char&)'
[ILINK32 错误] 错误:未解析的外部 'std::locale::id::operator unsigned int()'
[ILINK32 错误] 错误:未解析的外部 'std::locale::name() const'
[ILINK32 错误] 错误:未解析的外部 'std::codecvt_base::codecvt_base(unsigned int)'
[ILINK32 错误] 错误:未解析的外部 'std::locale::facet::_Incref()'
[ILINK32 错误] 错误:未解析的外部 'std::ios_base::ios_base()'
[ILINK32 错误] 错误:未解析的外部 'std::ios_base::getloc() const'
[ILINK32 错误] 错误:未解析的外部 'std::ctype::_Getcat(std::locale::facet * *, std::locale *)'
[ILINK32 错误] 错误:未解析的外部 'std::ctype::widen(char) const'
[ILINK32 错误] 错误:未解析的外部 'std::ios_base::rdstate() const'
[ILINK32 错误] 错误:无法执行链接
还有其他将文件读入字符串的解决方案吗?
【问题讨论】:
-
检查您的库路径。您的标准库可能存在一些配置问题。
-
@Devolus : intsand of ifstream , 在 Borland C++, RAD XE Embarcadero IDE 中读取文件有什么解决方案吗?
-
您的问题不是标准库函数,而是您的设置。作为旁注,您发布的内容无论如何都不是正确的 C++ 代码,因此您无论如何都应该发布一个完整的示例。
-
@Devolus :我在这里写了给出错误的代码。我的目标是创建读取整个大文件数据并将文件内容返回到字符串变量的函数。项目又大又旧,所以我目前无法对配置/设置进行重大更改。
-
为什么在 VCL 中使用 iostream 和 fstream?您在 VCL 中原生获得了
AnsiString...TStrings和TMemo->Lines可以使用简单的LoadFromFile方法加载整个文本文件。文件访问也很简单,使用VCL:FileOpen/FileCreate, FileSeek, FileRead/FileWrite, FileClose。但是对于您的错误,您的项目配置错误,因此可能是您在项目文件中有一些奇怪的设置或损坏......有时创建新的会有所帮助。Unresolved external表示您已包含标头但没有代码,也没有链接 obj/lib/dll
标签: c++ c++builder vcl c++builder-xe