机器人以某种方式转换流类型吗?

时间:2016-03-01 18:56:54

标签: c++ stringstream anonymous static-cast manipulators

我尝试使用匿名ostringstream来生成stringUse an Anonymous Stringstream to Construct a String

然而,当我使用操纵器时,我似乎无法再编译:

const auto myString(static_cast<ostringstream>(ostringstream{} << setfill('!') << setw(13) << "lorem ipsum").str());

但似乎不允许even in gcc 5.1

  

prog.cpp:在函数int main()中:
  prog.cpp:8:109:错误:没有匹配函数来调用std::basic_ostringstream<char>::basic_ostringstream(std::basic_ostream<char>&)
    const auto myString(static_cast<ostringstream>(ostringstream{} << setfill('!') << setw(13) << "lorem ipsum").str());
  

  在/ usr / include / c ++ / 5 / iomanip中包含的文件中:45:0,
                   来自prog.cpp:1:
  / usr / include / c ++ / 5 / sstream:582:7:注意:候选人
  std::basic_ostringstream<_CharT, _Traits, _Alloc>::basic_ostringstream(std::basic_ostringstream<_CharT, _Traits, _Alloc>&&) [与_CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
         basic_ostringstream(basic_ostringstream&& __rhs)
  
  / usr / include / c ++ / 5 / sstream:582:7:注意:从std::basic_ostream<char>std::basic_ostringstream<char>&&的参数1没有已知的转换
  / usr / include / c ++ / 5 / sstream:565:7:注意:候选人:
  std::basic_ostringstream<_CharT, _Traits, _Alloc>::basic_ostringstream(const __string_type&, std::ios_base::openmode) [与_CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_ostringstream<_CharT, _Traits, _Alloc>::__string_type = std::basic_string<char>; std::ios_base::openmode = std::_Ios_Openmode]
         basic_ostringstream(const __string_type& __str,
  
  / usr / include / c ++ / 5 / sstream:565:7:注意:从std::basic_ostream<char>const __string_type& {aka const std::basic_string<char>&}的参数1没有已知的转换
  / usr / include / c ++ / 5 / sstream:547:7:注意:候选人:
  std::basic_ostringstream<_CharT, _Traits, _Alloc>::basic_ostringstream(std::ios_base::openmode) [与_CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::ios_base::openmode = std::_Ios_Openmode]
         basic_ostringstream(ios_base::openmode __mode = ios_base::out)
  
  / usr / include / c ++ / 5 / sstream:547:7:注意:参数1从std::basic_ostream<char>std::ios_base::openmode {aka std::_Ios_Openmode}没有已知转换

这是另一个gcc流错误,还是我实际上做的非法?

1 个答案:

答案 0 :(得分:3)

 "int func1(int a[][],int b[][], column, row)" 

这将尝试从parens中的参数构造一个新的static_cast<ostringstream>(...) ostringstream,其中没有std::ostringstream的构造函数。

您只想将引用转换回原始类型。使演员阵容参考:

std::ostream&

然后它工作正常。

我不知道你的想法是什么,但是遗漏了引用,并删除了操纵器,它仍然失败。