小编pir*_*ill的帖子

将字符串转换为double的C++错误

我正在尝试将字符串转换为double.代码很简单.

            double first, second;
            first=atof(str_quan.c_str());
            second=atof(extra[i+1].c_str());
            cout<<first<<" "<<second<<endl;
            quantity=first/second;
Run Code Online (Sandbox Code Playgroud)

当试图转换额外的时候,编译器会向我抛出这个智慧的宝石:

错误:在extra.std中请求成员c_str :: basic_string <_CharT,_ Traits,_Alloc> :: operator [] [with _CharT = char,_Traits = std :: char_traits,_Alloc = std :: allocator](((unsigned int )(i + 1))),它是非类型char

我不知道这意味着什么.如果我输出额外的[i + 1],我得到3.如果我将额外的字符串作为字符串,程序会尝试将第一个(2)除以51(ascii为3).到底他妈发生了什么?

c++ atof

1
推荐指数
1
解决办法
6559
查看次数

标签 统计

atof ×1

c++ ×1