我從文件中添加一個double值到一個變量,並將其推入一個向量中,格式爲「338620.3478」,然後從該向量獲得值,它只獲得「338620」,因爲它無法獲得所有的雙重價值。獲取完整的雙倍值
那麼我怎樣才能得到像原始格式的完整雙值?
的代碼:
struct Point {
double x, y;
bool operator <(const Point &p) const {
return x < p.x || (x == p.x && y < p.y);
}
};
ifstream iFile("griddata.dat"); //read a file (grid)
string line;
Point Grid;/
while(getline(iFile,line))
{
unsigned pos = line.find(",");//the symbol is used to separate X and Y
std::string strs = line.substr(0,pos); // get X
std::string strs2 = line.substr(pos+1); // get Y
Grid.x = atof(strs.c_str()); // get the first cooordinate X
Grid.y = atof(strs2.c_str()); // get the second cooordinate Y
// A list of coordinates of grid is stored into the vector gridPoints
gridPoints.push_back(Grid); // adding the points of grid to vector
}
int j;
for(j=0;j<gridPoints.size();j++)
{
//here i cannot get the full double value for gridPoints[j].x;
//....it just gets "338620"
}
文件的格式(griddata.dat):
338620.3478,6196150.566
謝謝!
請出示一些代碼... –
能否請您提供更多相同的細節。你可以在這裏發佈你的代碼,這樣很容易解決問題。 :) –
你應該顯示你的代碼。否則,我們只能猜測什麼是錯的。 – crashmstr