にはどうすればC++にSTOD()またはにstrtod()を使用せずに、私のreadDetails機能を書き換えることができますか? ++ 11が有効になっており、私はどのように私は(STODなしに書き換えることができます)
「STOD」はこのスコープのエラー以下
int readDetails(SmallRestaurant sr[])
{
//Declaration
ifstream inf;
//Open file
inf.open("pop_density.txt");
//Check condition
if (!inf)
{
//Display
cout << "Input file is not found!" << endl;
//Pause
system("pause");
//Exit on failure
exit(EXIT_FAILURE);
}
//Declarations and initializations
string fLine;
int counter = 0;
int loc = -1;
//Read
getline(inf, fLine);
//Loop
while (inf)
{
//File read
loc = fLine.find('|');
sr[counter].nameInFile = fLine.substr(0, loc);
fLine = fLine.substr(loc + 1);
loc = fLine.find('|');
sr[counter].areaInFile = stod(fLine.substr(0, loc)); //line using stod
fLine = fLine.substr(loc + 1);
loc = fLine.find('|');
sr[counter].popInFile = stoi(fLine.substr(0, loc));
fLine = fLine.substr(loc + 1);
sr[counter].densityInFile = stod(fLine); //line using stod
counter++;
getline(inf, fLine);
}
//Return
return counter;
}
で宣言されていなかった得るcは、私が使用することになります コンパイラが持っていない私は読んしようとしているテキストです。
国勢調査トラクト201、オートーガ郡、アラバマ州| 9.84473419420788 | 1808年| 183.651479494869 国勢調査トラクト202、オートーガ郡、アラバマ州| 3.34583234555866 | 2355年| 703.860730836106 国勢調査トラクト203、オートーガ郡、アラバマ州| 5.35750339330735 | 3057 | 570.60159846447
さあ、これは彼らが求めている変換でさえない。また、それは明らかにいくつかの詐欺です。 –
@BaummitAugen:文字列を10進数(数値)に変換することを尋ねています。これは 'std :: istringstream'の動作です。 –
@BaummitAugen:ファイルの読み方については、たくさんの投稿がありますが、それらはすべて少し異なります。これは '|'セパレータとしてだけでなく、 '、'。 –