我正在进行编程-- Bjarne的原理和实践,一个相当简单的练习让我陷入困境(这只是11部分中的第2部分)。
#include "../../std_lib_facilities.h"
#include <stdlib.h>
//Write a program that consists of a while loop (each time around the loop) reads in two ints and then prints them. Exit the program when a terminating | is entered.
int main()
{
char temp;
char* endptr = 0;
while (temp != '|')
{
double value;
vector<int> values;
for (string temp; values.size() < 2;)
{
cin >> temp;
{
if (temp == "|")
break;
else
value = strtod(temp, &endptr);
values.push_back(value);
}
}
cout << values[0] << "\n" << values[1] << "\n" << "\n";
values.clear();
}
}2017在这里给了我一个错误:
else
value = strtod(temp, &endptr); 使用参数temp建议“从"std::string”到"const *“不存在合适的转换函数”,这正是我所期望的strtod函数。
发布于 2018-11-09 13:32:56
在C++中,使用std::stod()代替(C++11)
https://stackoverflow.com/questions/53226513
复制相似问题