C风格的字符串,就是一个以0字符结束的字符数组,

我们知道,C++提供了string这个标准库用以支持对字符串的处理,我们能很方便的将一个C风格的字符串放进一个string, 不过当我们在调用一些以C风格字符串为参数的函数的时候,就需要以C风格字符串的形式提取出string的值,

这里,c_str()能完成这件事

string str = "c style string!";
void f() {
     printf("the c style string:%s.\n", str.c_str())  
}

  

相关文章:

  • 2021-09-29
  • 2022-12-23
  • 2021-07-09
  • 2021-07-31
  • 2018-12-15
  • 2022-02-17
  • 2021-05-04
猜你喜欢
  • 2022-01-19
  • 2021-05-31
  • 2021-11-22
  • 2021-05-28
  • 2022-12-23
相关资源
相似解决方案