假设我有函数foo(string& s)
。如果我得到 C string
,foo(char* s)
,我会简单地将函数称为 foo("bar")
。< br/>
我想知道我是否能以某种方式在 C++ String
中做到这一点?
以某种方式缩短它:
string v("bar");
foo(v)
我正在使用 Linux GCC C++。
最佳答案
它不起作用,因为参数必须是 const
引用:
void foo( const std::string& s )
// ^^^^^
foo( "bar" ); // will work now
关于c++ - 有什么方法可以缩短 C++ 中的 String 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22451423/