可以这样写吗?如果不行该怎么办呢?

灌水区

dAniel_lele @ 2021-06-03 21:39:17

出题时偷个懒qwq

freopen((k+".in").c_str,"w",stdout);

(k是一个字符串)


by _caiji_ @ 2021-06-03 21:42:59

/tmp/compiler_xu137fsj/src: 在函数‘int main()’中:
/tmp/compiler_xu137fsj/src:6:39: 错误:对非静态成员函数‘const _CharT* std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::c_str() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’的使用无效
     freopen((k+".in").c_str,"w",stdout);
                                       ^
In file included from /usr/include/c++/8/string:52,
                 from /tmp/compiler_xu137fsj/src:1:
/usr/include/c++/8/bits/basic_string.h:2290:7: 附注:在此声明
       c_str() const _GLIBCXX_NOEXCEPT
       ^~~~~

by _caiji_ @ 2021-06-03 21:44:27

其实可以用,是您写错了,应该这样写:

freopen((k+".in").c_str(),"w",stdout);
//                     ^~

by dAniel_lele @ 2021-06-03 21:48:12

@caijianhong 我tmsb!


by zhuzhu2891 @ 2023-10-13 10:45:13

考古早期zxx珍贵影像


|