C++ 读取所有字符,包括空字节
我想从文件中读出chrome的历史记录。我想获取该文件中的所有字符和空字节。我面临的问题是,我只能得到文件中的部分文本。我相信它会因为一个空字节或一个特殊字符而停止 这是我目前的代码C++ 读取所有字符,包括空字节,c++,string,null,byte,C++,String,Null,Byte,我想从文件中读出chrome的历史记录。我想获取该文件中的所有字符和空字节。我面临的问题是,我只能得到文件中的部分文本。我相信它会因为一个空字节或一个特殊字符而停止 这是我目前的代码 #include <iostream> #include <fstream> #include <string> #include <sstream> using namespace std; int main(){ string str; st
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string str;
std::ifstream in("c:/Users/Petrus/Documents/History"); // I have copy my file into my documents to make sure I'm not interfering with Chrome.
std::stringstream buffer;
if (!in.is_open()){
cout << "Failed to open" << endl;
}
else{
cout << "Opened OK" << endl;
}
buffer << in.rdbuf();
std::string contents(buffer.str());
while (getline(buffer, str))
{
cout << str;
}
in.close();
system("PAUSE");
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
字符串str;
std::ifstream-in(“c:/Users/Petrus/Documents/History”);//我已经将文件复制到文档中,以确保不会干扰Chrome。
std::stringstream缓冲区;
如果(!in.is_open()){
coutstd::getline()
应仅用于读取纯文本文件
要读取任意二进制文件,应使用read()
。此外,在您的操作系统上,您必须使用std::ios::binary
标志打开二进制文件。我不知道它在Windows上是如何运行的,但在我的Linux系统上,历史数据库只是一个数据库,更确切地说是一个数据库。因此,如果您想进行一些处理或从中获取信息,您可能应该使用使用正确的工具(即)打开并阅读。