怎么样将txt中的数据按如下格式保存到数组中

C++语言 码拜 8年前 (2016-06-10) 821次浏览
怎么样将txt中的数据按如下格式保存到数组中怎么样将txt中的数据按如下格式保存到数组中
一个TXT文档如图一,怎么把他存到以图二中的格式存到uchar数组中。
解决方案

10

数组没有啥格式,就一个类型,你定义一个unsigned char类型的数组,再写一个读txt的函数就可以了

2

00, 01 …是什么类型?假如是字符串要用双引号。

2

假如是unsigned char,那么01只能存为1吧

6

unsigned char 只能是一个字符  前边的0没有意义  去掉0可以实现
#include <iostream>
#include<string>
#include <fstream>
using namespace std;
int main()
{
fstream outfile;
string filename = “aa.txt”;
outfile.open(filename, ios::out | ios::in);
if (!outfile)
{
cerr << “open file error” << endl;
return 1;
}
string str;
unsigned char data1[100] = {0};
int i = 0;
for (str; getline(outfile, str);)
for (auto c : str)
{
if (!isspace(c))
{
data1[i] = c;
i++;
}
}
cout << data1 << endl;
outfile.close();
getchar();
return 0;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样将txt中的数据按如下格式保存到数组中
喜欢 (0)
[1034331897@qq.com]
分享 (0)