- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我第一次使用QString,我不知道如何解决此错误:
Personanetscape.cpp:16:错误:没有匹配的函数可以调用“std::basic_ifstream::basic_ifstream(QString&)”
这是我的.h
#include <iostream>
#include <fstream>
#include <string>
#include <qstring.h>
#include <qmap.h>
typedef QMap<QString, QString> Map;
class PersonaNetscape
{
private:
std::ifstream fileIn;
Map map;
public:
PersonaNetscape(QString nameFileIn);
~PersonaNetscape();
bool personIn();
QString search(QString field);
};
#include "Personanetscape.h"
PersonaNetscape::PersonaNetscape(QString nameFileIn)
: fileIn(nameFileIn) //this is line 16 in my code
{
if(!fileIn)
throw nameFileIn;
}
最佳答案
使用QFile代替std::ifstream。
我最初首选QFile而不是std::ifstream的原因是因为通常来说,如果我正在编写使用QString的代码(或另一个Qt框架类),并且还有其他Qt框架类可以实现我想做的事情(在这种情况下(QFile),我会更喜欢这样做,因为它会变得更容易,而且我不必担心转换类型/奇怪的情况。
Scheff添加了一个很好的理由,在使用我完全忽略的QString时更喜欢QFile。他说:
std::string is actually encoding agnostic where QString provides methods to convert to and from various encodings, and the internal handling of strings in Qt is done with a well-defined encoding. Hence, the usage of QFile will prepare the application for better handling of encoding and locale stuff than "the hack" with .toStdString().c_str().
关于c++ - 没有匹配的函数来调用 ‘std::basic_ifstream<char>::basic_ifstream(QString&)’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60984371/
这是我第一次使用QString,我不知道如何解决此错误: Personanetscape.cpp:16:错误:没有匹配的函数可以调用“std::basic_ifstream::basic_ifstre
我正在尝试编写一个程序来打开一个文件并计算该文件中以空格分隔的单词数。 #include #include #include using namespace std; int main() {
从这段代码构建的程序: #include using std::basic_ifstream; #include using std::streamsize; #include using Ze
我有一个二进制文件。上半部分存储了2288*2288个经度浮点值,同样数量的纬度浮点值占据了下半部分。我使用以下代码将它们加载到浮点 vector 中。它可以像魅力一样运行,但给了我不正确的结果。关于
我应该编写一个程序,合并两个文件中的数字并将所有数字写入第三个文件。该程序从两个不同的文件中获取输入并将其输出写入第三个文件。每个输入文件都包含一个按从小到大排序的 int 类型数字列表。程序运行后,
这可能吗?我一直在尝试读取一个包含俄语的简单文件,但显然无法正常工作。 我调用了 file.imbue(loc)(此时,loc 是正确的,Russian_Russia.1251)。而 buf 的类型是
我正在尝试使用以下代码从文件中读取数据。 (请注意,您需要在 GCC 上启用 C++11 功能才能进行此编译。) #include typedef unsigned char byte; int m
我想不通,是否可以将 std::basic_ifstream 和 std::basic_ofstream 与 std::basic_filebuf 的自定义实现一起使用? 按 64KB 大小的 blo
我在图像处理的上下文中学习 IO,这是我第一次不得不将流用于二进制文件而不是格式化/文本文件。我正在尝试使用带有模板编程的重载流插入运算符将位图的前 14 个字符读入结构。 #include #in
以下代码按预期工作。源代码,文件“file.txt”和“out.txt”都是用utf8编码的。但是当我改变时它不起作用wchar_t至 char16_t在 main() 的第一行.我用 -std=c+
以下代码按预期工作。源代码、文件“file.txt”和“out.txt”都是用utf8编码的。但是,当我在 main() 的第一行将 wchar_t 更改为 char16_t 时,它不起作用。我已经用
当我尝试运行它时: #include #include int _tmain(int argc, TCHAR *argv[]) { std::basic_ifstream file("Te
There are already questions在 Stackoverflow 上询问 为什么 basic_fstream不起作用。答案说char_traits仅专门用于 char和 wchar
上面写着“Apple Mach-O Linker (Id) Error "readIt(std::_1::basic_ifstream >&," 有没有人看到它一直卡住的错误?非常感谢! #inclu
我是一名优秀的程序员,十分优秀!