佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2181|回复: 3

FILE* fp = fopen(weight.c_str(),"r"); .c_str()是什么??

[复制链接]
发表于 28-3-2012 04:51 PM | 显示全部楼层 |阅读模式
FILE* fp = fopen(weight.c_str(),"r"); 我只学到了用file来开.txt file。。。。但是.c_str()是代表什么呢??
可以在project folder里面找到的吗??
回复

使用道具 举报


ADVERTISEMENT

发表于 29-3-2012 01:17 AM | 显示全部楼层
本帖最后由 yeenfei 于 29-3-2012 01:38 AM 编辑

"weight" should be a std::string variable declared earlier
"weight" 应该是之前声明的字符串类变量

fopen() is the function used to access disk file (can be read or write). It expects the first parameter to be "pointer to char" (thus std::string object cannot be used directly) which is memory location of a string data specifying the target path.
fopen() 是用来进行硬碟文件操作(导入或输出)的函数,它要求其第一个输入值为 "字符的指针" (所以不能直接挪用字符串类物件) ,也就是为目标文件名的字符串位置。

c_str() is member function of std::string that returns the starting address of memory holding string data in "pointer to char" format (hence matches the type requirement for function parameter above).
c_str() 则是一个字符串类的函数,以"字符的指针" 方式来返回内部的字符串位置(所以符合上面函数输入值的类要求)



偶怕被扣分,所以用半桶水的中文解释一下
回复

使用道具 举报

 楼主| 发表于 29-3-2012 01:08 PM | 显示全部楼层
所以c_str()只是类似一个address他是不存在在我们project folder 里面的咯?
回复

使用道具 举报

发表于 2-4-2012 03:33 PM | 显示全部楼层
.c_str() 简单来说就是把string 转成 char * 而已。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 2-11-2025 02:58 AM , Processed in 0.118026 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表