C++17才有支持吧?
之前linux上是char,windows才是wchar_t
【 在 zhanghaoX (环顾四方有效) 的大作中提到: 】
: 标 题: 奇怪的问题: Debian的头文件 ?
: 发信站: 水木社区 (Thu Jun 18 16:10:31 2020), 站内
:
: 【 以下文字转载自 LinuxDev 讨论区 】
: 发信人: zhanghaoX (环顾四方有效), 信区: LinuxDev
: 标 题: 奇怪的问题: Debian的头文件 ?
: 发信站: 水木社区 (Thu Jun 18 16:10:10 2020), 站内
:
:
: Debian10 编译一个C++程序 ,
:
: const wchar_t* szFileName,
: ofstream ofs;
: ofs.open( szFileName , std::ios::out ) ;
:
: 报错:
:
: error: no matching function for call to ‘std::basic_ofstream<char>::open(const wchar_t*&, const openmode&)’
: ofs.open( szFileName , std::ios::out ) ;
: ^
: In file included from /home/a/share/xxxx.cpp:9:
: /usr/include/c++/8/fstream:851:7: note: candidate: ‘void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]’
: open(const char* __s, ios_base::openmode __mode = ios_base::out)
: ^~~~
: /usr/include/c++/8/fstream:851:7: note: no known conversion for argument 1 from ‘const wchar_t*’ to ‘const char*’
: /usr/include/c++/8/fstream:871:7: note: candidate: ‘void std::basic_ofstream<_CharT, _Traits>::open(const string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::__cxx11::string = std::__cxx11::basic_string<char>; std::ios_base::openmode = std::_Ios_Openmode]’
: open(const std::string& __s, ios_base::openmode __mode = ios_base::out)
: ^~~~
: /usr/include/c++/8/fstream:871:7: note: no known conversion for argument 1 from ‘const wchar_t*’ to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
: make[2]: *** [oooooo/CMakeFiles/oooooo.dir/build.make:102: oooooo/CMakeFiles/oooooo.dir/oooooo.cpp.o] Error 1
: make[2]: *** Waiting for unfinished jobs....
:
:
:
: 头文件竟然没有 wchar_t* 的
: /usr/include/c++/8/fstream:
:
: /**
: * @brief Opens an external file.
: * @param __s The name of the file.
: * @param __mode The open mode flags.
: *
: * Calls @c std::basic_filebuf::open(s,__mode|in). If that function
: * fails, @c failbit is set in the stream's error state.
: */
: void
: open(const char* __s, ios_base::openmode __mode = ios_base::in)
: {
: if (!_M_filebuf.open(__s, __mode | ios_base::in))
: this->setstate(ios_base::failbit);
: else
: // _GLIBCXX_RESOLVE_LIB_DEFECTS
: // 409. Closing an fstream should clear error state
: this->clear();
: }
:
: #if __cplusplus >= 201103L
: /**
: * @brief Opens an external file.
: * @param __s The name of the file.
: * @param __mode The open mode flags.
: *
: * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
: * fails, @c failbit is set in the stream's error state.
: */
: void
: open(const std::string& __s, ios_base::openmode __mode = ios_base::in)
: {
: if (!_M_filebuf.open(__s, __mode | ios_base::in))
: this->setstate(ios_base::failbit);
: else
: // _GLIBCXX_RESOLVE_LIB_DEFECTS
: // 409. Closing an fstream should clear error state
: this->clear();
: }
:
: #if __cplusplus >= 201703L
: /**
: * @brief Opens an external file.
: * @param __s The name of the file, as a filesystem::path.
: * @param __mode The open mode flags.
: *
: * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
: * fails, @c failbit is set in the stream's error state.
: */
: template<typename _Path>
: _If_fs_path<_Path, void>
: open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
: { open(__s.c_str(), __mode); }
: #endif // C++17
: #endif // C++11
:
: /**
: * @brief Close the file.
: *
: * Calls @c std::basic_filebuf::close(). If that function
: * fails, @c failbit is set in the stream's error state.
: */
: void
: close()
: {
: if (!_M_filebuf.close())
: this->setstate(ios_base::failbit);
: }
: };
:
:
:
:
: --
:
: ※ 来源:·水木社区
http://newsmth.net·[FROM: 121.69.79.*]
--
FROM 76.126.252.*