We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
对于我这种C++新人来说,用C++干个啥都很困难,似乎都需要记录。比如近日有这么一个需求,把一个二进制文件(old.wav)读取到内存里,返回给调用方,然后调用方在把它写入到一个新的二进制文件(new.wav)中。
#include <iostream> #include <vector> #include <fstream> std::vector<char> read_return() { std::ifstream file("old.wav", std::ios::binary | std::ios::ate); std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); std::vector<char> buffer(size); if (file.read(buffer.data(), size)) { std::cout << "Read OK!" << std::endl; return buffer; } else { std::cout << "Read Failed!" << std::endl; return buffer; } } int main() { auto wav = read_return(); std::ofstream stream("save.wav", std::ios::binary); stream.write((const char *) &wav[0], wav.size()); stream.close(); return 0; }
参考:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
对于我这种C++新人来说,用C++干个啥都很困难,似乎都需要记录。比如近日有这么一个需求,把一个二进制文件(old.wav)读取到内存里,返回给调用方,然后调用方在把它写入到一个新的二进制文件(new.wav)中。
参考:
The text was updated successfully, but these errors were encountered: