|
查看: 2181|回复: 3
|
FILE* fp = fopen(weight.c_str(),"r"); .c_str()是什么??
[复制链接]
|
|
|
FILE* fp = fopen(weight.c_str(),"r"); 我只学到了用file来开.txt file。。。。但是.c_str()是代表什么呢??
可以在project folder里面找到的吗?? |
|
|
|
|
|
|
|
|
|
|
发表于 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 * 而已。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|