[問題] 新手問題關於字串轉浮點數

看板C_and_CPP (C/C++)作者 (只想做個閒人= =)時間16年前 (2009/05/10 21:00), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
問題是這樣的 我將0.45這個數字放在.txt檔裡 然後用substr()讀入成字串型態 接著我想做運算 就只是 1 - 0.45 而已 我試了atof()有錯: 'atof' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char 想請各位幫幫忙 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.66.134.94

05/10 21:16, , 1F
他吃const char* 你給他string 呼叫c_str()吧
05/10 21:16, 1F
文章代碼(AID): #1A1i_NPe (C_and_CPP)
文章代碼(AID): #1A1i_NPe (C_and_CPP)