【发布时间】:2014-03-24 03:20:33
【问题描述】:
我有一个函数,它接收一个指向要打开的文件名的字符串的指针,并用 1 和 0 进行编码; codedLine 包含类似 010100110101110101010011 的内容 写入二进制文件后,我完全一样......你会推荐吗?谢谢。
void codeFile(char *s)
{
char *buf = new char[maxStringLength];
std::ifstream fileToCode(s);
std::ofstream codedFile("codedFile.txt", std::ios::binary);
if (!fileToCode.is_open())
return;
while (fileToCode.getline(buf, maxStringLength))
{
std::string codedLine = codeLine(buf);
codedFile.write(codedLine.c_str(), codedLine.size());
}
codedFile.close();
fileToCode.close();
}
【问题讨论】:
-
你到底在问什么?
-
问题是我不能将例如 101010101 的字符串写成二进制