我有一個結構與x,y,z作爲類型雙。我試圖通過空格拆分這些行,然後將該數組的值放入我的結構中,但它無法工作,有人可以告訴我該怎麼辦?如何將char *轉換爲雙精度?
#include "_externals.h"
#include <vector>
typedef struct
{
double X, Y, Z;
} p;
p vert = { 0.0, 0.0, 0.0 };
int main()
{
char *path = "C:\\data.poi";
ifstream inf(path);
ifstream::pos_type size;
inf.seekg(0, inf.end);
size = inf.tellg();
double x, y, z;
char *data;
data = new char[size];
inf.seekg(inf.beg);
inf.read(data, size);
inf.seekg(inf.beg);
char** p = &data;
char *line = *p;
for (int i = 0; i < strlen(data); ++i)
{
const char *verts = strtok(line, " ");
//this isnt working
vert.X = verts[0];
vert.Y = verts[1];
vert.Z = verts[2];
++*line;
}
}
感謝
什麼是綠黨? – soandos
你的數據文件每行3倍,每個文件用空格分隔嗎?只是好奇。 – WhozCraig
扁豆... – Potatoswatter