【发布时间】:2018-11-20 15:52:44
【问题描述】:
我想从读取文件转移字符数组并写入输出。但我有 2 个错误。我不知道这个错误。
没有合适的从“std::valarray”到“const”的转换函数 char *" 存在
'std::basic_ostream> &std::basic_ostream>::write(const _Elem *,std::streamsize)': 无法将参数 1 从 'std::valarray' 转换为 'const _Elem *'
void CaesarCipher(std::wstring i_inputFilePath, std::wstring o_outputFilePath, int shift)
{
ifstream file(i_inputFilePath, ios::binary);
if (file.is_open())
{
ofstream output(o_outputFilePath, ios::binary);
std::array<char, 1024> buffer;
while (!file.eof()) {
file.read(buffer.data(), buffer.size());
std::rotate(buffer.begin(), std::next(buffer.begin(), shift), buffer.end());
output.write(buffer, buffer.size());
}
output.close();
file.close();
}
else
{
cout << "File is not exist";
}
}
int main()
{
CaesarCipher(L"D:/input.exe", L"D:/output.exe", 1);
}
【问题讨论】:
-
关于
while(!file.eof())的值得一读:stackoverflow.com/questions/5605125/… -
@Galik 我对读取块文件没有问题。我已经在我的项目中对其进行了测试。如何将数据从文件中读取和写入的问题。
-
我不是想回答你的问题。我只是指出你的代码中的一个错误。
-
您已经更改了代码,所以现在问题描述和错误消息不再有意义。
-
关于标签 visual-studio 的无关注释。如果您阅读说明,它会说 不要在有关代码的问题上使用此标记,而这些代码恰好是用 Visual Studio 编写的。,因此不应在此问题中使用它。类似情况适用于 Linux 和 Windows 标记。
标签: c++ linux windows visual-studio