c_str()函数返回一个指向正规C字符串的指针, 内容与string串相同.将string转化成const char*。
标准C++库字符串类的一个成员函数,因为system函数只接受const char*类型的参数,而不是const std::string&,你就需要把后者转换为前者。c_str()就是做这个用的。所谓C风格的字符串,就是以\0作为结束符的字符串表达方法。
Converts the contents of a string as a C-style, null-terminated string.
const value_type *c_str( ) const;
Return Value
A pointer to the C-style version of the invoking string. The pointer value is not valid after calling a non-const function, including the destructor, in the basic_string class on the object.
Converts the contents of a string as a C-style, null-terminated string.
const value_type *c_str( ) const;
Return Value
A pointer to the C-style version of the invoking string. The pointer value is not valid after calling a non-const function, including the destructor, in the basic_string class on the object.