C++中文件名称必须是C风格的char*格式
2012-01-04 11:30
176 查看
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类型的.
使用 c_str() 函数转格式即可.
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类型的.
使用 c_str() 函数转格式即可.
相关文章推荐
- C++中文件名称必须是C风格的char*格式
- c++对文件进行操作之读取文件夹下面的图片名称
- C++ 头文件格式和函数注释格式
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- PADS下建立器件类型时怎么快速输入管脚名称----使用CSV/Excel/Txt格式文件
- C/C++中文件的读写格式
- 写一个脚本,对一个文件夹内指定格式的文件做重命名处理,要求:重命名为数字编号从1开始,当有新增文件的时候,自动重名并跟随末尾编号格式,中间删减的时候,末尾名称自动改名补回空缺序号
- 基于C++和MFC遍历指定文件夹下指定格式的文件
- 悦铃文件必须是CCITT A_Law格式的,且没有被压缩
- 读取DXF格式文件的C++代码
- c++某种文件格式的读取与写入范例[stl]
- C++ 头文件格式和函数注释格式
- C++风格_格式
- C++实现所有文件格式复制
- 无法创建.gitignore文件,提示必须输入文件名称
- unbuntu 下更改vim配置文件,打造C/C++风格
- C++、WIN API、MFC分别遍历文件夹、获取文件名称的三种方式【耿然原创】
- 一个关于读取指定路径下文件名称的小工具(C++)
- c++某种文件格式的读取与写入范例[stl]
- C/C++ 定义接口文件格式