关于strtod

来源:互联网 发布:红雪越狱工具mac 编辑:程序博客网 时间:2024/06/01 21:20

先看个简单例子:

#include <iostream>
using namespace std;


void change(char *s)
{

s++;//错误 并没有办法改变它的地址!!
}

int main()
{
char d[] = "dsaggd";
char *s = d;
change(s);
cout<<*s<<endl;
}

所以正确的想要改变s的地址的做法是采用指针的指针

#include <iostream>
using namespace std;


void change(char **s)
{

(*s)++;//正确,正确的修改了地址值
}

int main()
{
char d[] = "dsaggd";
char *s = d;
change(&s);
cout<<*s<<endl;
}

在函数change()中*s实际上是指向实参s地址的内容,而s又是存放字符串的地址,所以能做出相应的改变。


字符串转double

double strtod(const char *nptr, char **endptr);
char* p;

number_ = strtod(&buf_[curPos_], &p);


有个疑问,为什么用指针的指针?

因为指针传递本质上也是值传递,需要改变的是指针本身,而不是指针所指向的内容,所以用到指针的指针!




0 0
原创粉丝点击