带有gcc 7.4.0的奇怪std :: atof错误

时间:2020-03-04 12:45:45

标签: c++ atof gcc7

在具有Qt Creator(4.10)作为IDE / gcc 7.4.0的Ubuntu 18.0.4中,我的std :: atof出现了这种奇怪的行为:

当我从QtCreator在调试模式下运行时,它像往常一样解析字符串。但是当我正常运行时它会落地。

具有此行为的示例代码:

std::string exampleStr = "3.0303";
std::cout << "string value: " << exampleStr << std::endl;
std::cout << "double value - c_str(): " << std::atof(exampleStr.c_str()) << std::endl;

从IDE正常运行的输出:

字符串值:3.0303

双精度值-c_str():3

直接从可执行文件运行的输出:

字符串值:3.0303

双精度值-c_str():3

以调试模式输出:

字符串值:3.0303

双精度值-c_str():3.0303

我已经尝试过std :: stof和std :: strtof。两者都一样。有人知道这个错误的原因或解决方法吗?

编辑: 我已经解决了这个问题,但仍然想知道这种现象的原因。

std::string exampleStr = "3.0303";    
std::stringstream ss;
ss << exampleStr;
float val = 0;
ss >> val;
std::cout << "Float value: " << val << std::endl;

1 个答案:

答案 0 :(得分:1)

我已经更改了语言环境:

import thunk from 'redux-thunk';
import {composeWithDevTools} from 'redux-devtools-extension';

import rootReducer from './reducers'

const middleware = [thunk];
const initialState = {};

const store = createStore(rootReducer, initialState, composeWithDevTools(applyMiddleware(...middleware)));


export default store;

,它适用于调试和运行模式。有趣的是,在调试模式下运行的语言环境与正常运行时有所不同。 感谢所有答复。