C++有一串01字符序列,如何把它们转化为对应的二进制位的形式写入文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++有一串01字符序列,如何把它们转化为对应的二进制位的形式写入文件相关的知识,希望对你有一定的参考价值。

参考技术A #include<fstream.h>

char c[3] = '0','1','1';
string s("1010");
fstream f;
f.open("out.txt", ios::out | ios::trunc);
for(int i=0;i<3;++i)
out<<c[i];
for(i=0;i<s.size();++i)
out<<s[i];
f.close();本回答被提问者采纳

有一串json字符串,我需要将其中的时间格式从yyyy-M-d转换为yyyy/M/d,用c#的正则表达式替换的方法怎么写

如下2015-9-24转换为2015/9/24
["Data":null,"Time":"2015-9-24 0:00:00","Data":null,"Time":"2015-9-24 1:00:00","Data":null,"Time":"2015-9-24 2:00:00","Data":null,"Time":"2015-9-24 3:00:00","Data":null,"Time":"2015-9-24 4:00:00","Data":null,"Time":"2015-9-24 5:00:00","Data":null,"Time":"2015-9-24 6:00:00","Data":null,"Time":"2015-9-24 7:00:00","Data":null,"Time":"2015-9-24 8:00:00","Data":null,"Time":"2015-9-24 9:00:00","Data":null,"Time":"2015-9-24 10:00:00","Data":null,"Time":"2015-9-24 11:00:00","Data":null,"Time":"2015-9-24 12:00:00","Data":null,"Time":"2015-9-24 13:00:00","Data":null,"Time":"2015-9-24 14:00:00","Data":null,"Time":"2015-9-24 15:00:00","Data":null,"Time":"2015-9-24 16:00:00","Data":null,"Time":"2015-9-24 17:00:00","Data":null,"Time":"2015-9-24 18:00:00","Data":null,"Time":"2015-9-24 19:00:00","Data":null,"Time":"2015-9-24 20:00:00","Data":null,"Time":"2015-9-24 21:00:00","Data":null,"Time":"2015-9-24 22:00:00","Data":null,"Time":"2015-9-24 23:00:00","Data":null,"Time":"2015-9-25 0:00:00"]

 String s = "[\\"Data\\":null,\\"Time\\":\\"2015-9-24 0:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 1:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 2:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 3:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 4:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 5:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 6:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 7:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 8:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 9:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 10:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 11:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 12:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 13:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 14:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 15:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 16:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 17:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 18:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 19:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 20:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 21:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 22:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 23:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-25 0:00:00\\"]";
            Console.WriteLine(s);
            String s0 = Regex.Replace(s, "([0-9]4)-([0-9]1,2)-([0-9]1,2)", "$1/$2/$3");
            Console.WriteLine(s0);

参考技术A

你先试试查找是否成功再说:

201\\d-\\d-[123]\\d [\\d:]7

以上是关于C++有一串01字符序列,如何把它们转化为对应的二进制位的形式写入文件的主要内容,如果未能解决你的问题,请参考以下文章

c语言 把某一字符串中的其中一段字符串替换成另一串字符串。

如何将一棵树转化为对应的二叉树

c++字符串LPCTSTR格式转化为char*

有一串json字符串,我需要将其中的时间格式从yyyy-M-d转换为yyyy/M/d,用c#的正则表达式替换的方法怎么写

把Json字符串转化为对应的类

将字符串元素转换为整数C++ [重复]