私は持っていstd::vector<std::string> WorldData
ます。world.txt というファイルのすべての行が含まれています (opengl 3d コーディネーションがあります)。次のようになります。
-3.0 0.0 -3.0 0.0 6.0
-3.0 0.0 3.0 0.0 0.0
3.0 0.0 3.0 6.0 0.0 etc.
これらの文字列を float 変数に変換するにはどうすればよいですか? 私が試したとき:
scanf(WorldData[i].c_str(), "%f %f %f %f %f", &x, &y, &z, &tX, &tY);
or
scanf(WorldData[i].c_str(), "%f %f %f %f %f\n", &x, &y, &z, &tX, &tY);
変数 x、y、z、tX、tY は奇妙な数値を取得します。