C++中文件名称必须是C风格的char*格式

1 篇文章 0 订阅
1 篇文章 0 订阅

File Names in C++
For historical reasons, the IO library uses C-style character strings (Section
4.3 , p. 130 ) rather than C++ strings to refer to file names. When we call
open or use a file name as the initializer when creating an fstream object, the
argument we pass is a C-style string, not a library string . Often our
programs obtain file names by reading the standard input. As usual, it is a
good idea to read into a string , not a C-style character array. Assuming
that the name of the file we wish to use is in a string , we can use the c_str
member (Section 4.3.2 , p. 139 ) to obtain a C-style string.

 

在C++ Primer一书中明确说明了,C++中读入文件操作(fstream类),中的文件名称必须是C_Style名称,

而是用C++ 时使用更多的是 library string , 利用string读入,调用函数c_str转换成char* (C_style)类型的文件

 

在OpenCV中的cvLoadImage参数也是char* 类型.

OpenCV中的imread 函数参数则是string类型的.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值