atof()无法阅读' e'在8e-6

时间:2016-08-27 22:33:08

标签: atof

我尝试逐字逐句地读取double的{​​{1}}类型值。在文件中我有一些值char buffer等。这是我的代码,它使用0.032 0.1234 8e-6 4e-3函数转换单词(存储在数组' atof()')到双值s

num

每当包含&#39; e&#39;在它们(如8e-6)中,atof()函数只为它们返回0。上述示例值的输出为char s[50]; double num; while(getline(str, line)) { int i=0, j=0; while(line[i] != '\0') { if(line[i] != ' ') { s[j] = line[i]; //cout << s[j]; <-- output of s[j] shows correct values (reading 'e' correctly) j++; } else { num = atof(s); cout << num << " "; j=0; } i++; } cout << endl; }

我尝试使用演示阵列进行检查,并且atof()工作正常。

0.032 0.1234 0 0

此处输出为char t[10]; t[0] = '8'; t[1] = 'e'; t[2] = '-'; t[3] = '5'; t[4] = '\0'; double td = atof(t); cout << "td = " << td << endl; 我已同时包含td = 8e-05<stdio.h>。知道为什么它不能正常工作吗?

1 个答案:

答案 0 :(得分:0)

您必须仅将import React, { Component } from 'react'; import { fabric } from 'react-fabricjs'; import styles from './MyComponent.css'; class MyComponent extends Component { constructor() { this.refs = { canvas: {} }; } componentWillMount() { // dispatch some actions if you use Redux } componentDidMount() { const canvas = new fabric.Canvas('c', { width: this.refs.canvas.clientWidth, height: this.refs.canvas.clientHeight }); this.fabric = canvas; // do some initial stuff with it } componentDidUpdate() { const { images = [] } = this.props; const { fabric } = this; // do some stuff as new props or state have been received aka component did update images.map((image, index) => { fabric.Image.fromURL(image.url, { top: 0, left: index * 100 // place a new image left to right, every 100px }); }); } render() { return ( <div className={styles.myComponent}> <canvas id="c" ref={node => { this.refs.canvas = node; } /> </div> ) } } 传递给函数atof(),否则返回值为0.

如果你要检查一个非常简单的代码     char p [] =&#34; 6e-5&#34 ;;     double a = atof(p); 你会发现它正在发挥作用。

这意味着您遇到的问题不是double号码,而是字符6e-5的错误表示。