我从文件中添加一个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