txt文件读取为char字符串并存入.h头文件中

博客介绍了在C++开发中,将txt文件转换为char字符串,还提到把printf的字符串加入数组a[],并将其变成stringstream流以进行文件写操作,聚焦于C++开发的文件处理。

txt转char字符串

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
int main() {
 std::ifstream inputFile("log2.txt");
    if (inputFile.is_open()) {
        std::ostringstream oss;
        // char c;
        unsigned char c;
        while (inputFile.get(reinterpret_cast<char&>(c))) {
            printf("0x%02x,", c);
        }
}

printf的字符串加入a[]中,可变成stringstream流进行文件写操作

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
unsigned char a[]={0x61,0x61,0x3a,0x31,0x32,0x35,0x20,0x2f,0x2f,0xe6,0x89};
int main() {
    string m((char *)a);
    stringstream b(m);
    std::string line;
    while (std::getline(b, line)) {
        std::cout << line << std::endl;
    }
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值