处理文件时,首选以下两个例子中的哪一个?一个人提供比另一个更好的表现吗?有什么不同吗?
ifstream input("input_file.txt");
ofstream output("output_file.txt");
Run Code Online (Sandbox Code Playgroud)
VS
fstream input("input_file.txt",istream::in);
fstream output("output_file.txt",ostream::out);
Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio2012。我有一张地图,看起来像这样:
std::map<std::string,std::map<std::unique_ptr<sf::Sound>,std::unique_ptr<sf::SoundBuffer>>> listSoundContainer;
Run Code Online (Sandbox Code Playgroud)
我正在尝试像这样插入数据:
std::unique_ptr<sf::SoundBuffer> soundBuffer(new sf::SoundBuffer());
if (soundBuffer->loadFromFile("assets/sound/" + _fileName) != false)
{
std::unique_ptr<sf::Sound> sound(new sf::Sound(*soundBuffer));
typedef std::map<std::unique_ptr<sf::Sound>, std::unique_ptr<sf::SoundBuffer>> innerMap;
listSoundContainer[_fileName].insert(innerMap::value_type(std::move(sound), std::move(soundBuffer)));
}
Run Code Online (Sandbox Code Playgroud)
并且即时通讯在编译时出现以下错误:
Microsoft Visual Studio 11.0 \ vc \ include \ utility(182):错误C2248:'std :: unique_ptr <_Ty> :: unique_ptr':无法访问类'std :: unique_ptr <_Ty>'1>中声明的私有成员1 >
[1> _Ty = sf ::声音1>] 1> c:\程序文件(x86)\ Microsoft Visual Studio 11.0 \ vc \ include \ memory(1447):请参见'std :: unique_ptr <_Ty>的声明: :unique_ptr'1> 1> [1> _Ty = sf :: Sound 1>] 1> c:\ program files(x86)\ microsoft visual …