c++ - 我们可以从文本文件中读取转义字符吗?
问题描述
我想像这样从文本文件中读取文本
文本文件:
This is some text \nThis is the next line
但是,当我将其读入字符串并输出时,我会得到类似这样的结果
This is some text \nThis is the next line
//Expected Output
This is some text
This is the next line
代码:
void LoadTexts(const std::string& filepath) {
std::ifstream reader(filepath);
if (reader.is_open()) {
while (!reader.eof()) {
std::string str;
while (true) {
std::string readStr;
//reader >> readStr;
std::getline(reader, readStr);
if (readStr == ">") break;
str += readStr;
}
texts.push_back(str);
}
reader.close();
}
}
解决方案
推荐阅读
- python - Python PyQt4 QFileDialog 图像并在 QListWidget 中加载
- c# - TFS 2015 Update 1 备份成功和失败警报不起作用
- javascript - 从 json 中获取特定值以放入数据数组
- c# - 温莎城堡:注入 IEnumerable
仅使用 IService 注册组件的子集 - graphql - 使用 GraphQL 查询获取最大值和最小值
- php - PHP If isset() 不返回 HTML 输入的值
- java - 我想知道在appium java中滚动的通用方法
- javascript - Redux reducer 中的扩展运算符
- tink - Google Tink:如何从 KeysetHandle 获取原始密钥字符串?
- ionic-framework - 构建版本 Ionic 不生成