Getline(); 提取以 1A 字符停止
Getline(); extraction stops with the 1A character
所以我不知道如何正确解释这一点,但我会尽力而为。
我正在尝试将文件保存到字符串中,它不是一个.txt文件,它是一个 .umsbt 文件,所以它有奇怪的 ASCII 字符(如 00、0A、0E、1A...(所以当我使用getline();
将 .umsbt 保存到字符串中,然后使用cout
打印它时,整个文件没有打印,当我通过 HxD(十六进制编辑器(打开实际文件时,我看到打印在 1A 字符之前停止, 做了一些测试,这是1A角色的错。
这是我的代码
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <string.h>
#include <conio.h>
#include <sstream>
using namespace std;
string line; //the file is stored here
string name; //name of the file
void printfile() {
int o = 0;
int fileCount;
ifstream file;
file.open(name, ios::in);
if (file.fail()) {
cout << "Not found n";
cin.get();
cin.get();
exit(1);
}else {
file.seekg(0, ios::end);
fileCount = file.tellg();
file.seekg(0);
while (!file.eof()) {
getline(file, line);
cout << "file character count: " << fileCount << endl;
cout << "string character count: " << line.length() << "n" << endl;
for (int i = 0; i < line.length(); i++) {
cout << line[i];
o++;
if (o == 16) {
cout << "n";
o = 0;
}
}
}
file.close();
}
}
int main()
{
cin.ignore(26, 'n');
cout << "Write the name of your file (.umsbt included) n" << endl;
cin >> name;
cout << "n";
printfile();
cin.get();
cin.get();
return 0;
}
希望有人可以帮助我,我目前正在尝试删除/替换任何文件中的所有 1A 字符,限制是您必须在 ifstream 本身中执行此操作,因为您无法将其保存在字符串中(会导致 1A 出现问题,文件不会完全保存(
(这是在HxD中打开的文件的图片,希望您了解它 https://i.stack.imgur.com/mpvY8.jpg(
提前谢谢你
似乎您使用的是二进制文件而不是普通的文本文件。 查看这些链接以了解二进制文件。
https://study.com/academy/lesson/writing-reading-binary-files-in-c-programming.html https://computer.howstuffworks.com/c39.htm
再见 塞缪尔
相关文章:
- C++字符*缓冲区的大小
- HEX值到wchar_t字符(UTF-8)的转换
- 为什么 Serial.println(<char[]>);返回随机字符?
- 我的字符计数代码计算错误.为什么
- 字符串-C++后显示的随机字符
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 如何在C++中从字符串中分割字符
- 为什么msgrcv()将垃圾字符馈送到缓冲区
- 指向指向字符数组的指针数组的指针
- 如何用转义符替换字符串中的所有特殊字符
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 比较字符数组
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何在C++中确定文本文件中的元素是字符还是数字
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++中无符号字符溢出
- Getline(); 提取以 1A 字符停止