int main()
{
std::stringstream s1("This is my string.");
std::stringstream s2 = s1; // error, copying not allowed
}
Run Code Online (Sandbox Code Playgroud)
我找不到为什么我不能复制stringstream的原因.你能提供一些参考吗?
我有一个成员,是std::ofstream fBinaryFile和
void setFile( std::ofstream& pBinaryFile )
{
fBinaryFile = pBinaryFile;
}
Run Code Online (Sandbox Code Playgroud)
输出:
Data.h:86:16: error: use of deleted function ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const
std::basic_ofstream<char>&)’
fBinaryFile = pBinaryFile;
^
Run Code Online (Sandbox Code Playgroud)
我明白std::ofstream不允许复制,也许我错过了一些东西.可以保存的内容pBinaryFile的fBinaryfile?
我知道已经有人问过类似的问题,但我无法通过查看类似的帖子找到答案。这是我的问题的最小工作示例,其中包含以下 C++ 代码:
#include <iostream>
#include <cstdio>
#include <fstream>
using namespace std;
class File{
public:
fstream value;
string name;
unsigned int number_of_lines;
};
void print_filename(File file){
cout << "Name of file is " << file.name << "\n";
}
int main(void){
File file;
print_filename(file);
cout << "\n";
return(0);
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我收到错误:
example.cpp: In function ‘int main()’:
example.cpp:28:22: error: use of deleted function ‘File::File(const File&)’
print_filename(file);
^
example.cpp:7:7: note: ‘File::File(const File&)’ is implicitly deleted because the default definition would be ill-formed:
class File{ …Run Code Online (Sandbox Code Playgroud)