trouble : convert string to double

i have problem when i had convert string to double variable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<fstream>
#include<string.h>
#include<sstream>
#include<vector>


using namespace std;

int main(){
	int cols,rows;
	cols=6;rows=15;
	string line;
	string **value;
	double *conv;
	string *rowsis;
	int i_line=0;
	int i,j,k,a,l;
	j=0;
	double ***datV;
	vector <string> v;
	vector <string> nVal;
	string delimiter="	";
	size_t pos=0;
	string token;
	ifstream fin("data/profil.data");
	while(getline(fin,line)){
		v.push_back(line);
		i_line++;
	}
	value=new string*[i_line];
	rowsis=new string[i_line];
	for(i=0;i<i_line;i+=18){
		a=1+i;
		rowsis[j]=v[i];
		value[j]=new string[rows];
		for(k=0;k<rows;k++){
			value[j][k]=v[a+k];
			while((pos=value[j][k].find(delimiter))!=string::npos){
				token=value[j][k].substr(0,pos);
				value[j][k].erase(0,pos+delimiter.length());
				nVal.push_back(token);
			}
			nVal.push_back(value[j][k]);
		}
		j++;
	}
	int limit=(j*rows-1)+(j*rows*cols);
	datV=new double**[i_line];
	conv=new double[limit];
	int b=0;
	for(i=1;i<limit;i++){
		stringstream vd(nVal[i]);
		vd>>conv[b];
		//view result variable conv
		cout<<conv[b];
		b++;
	}
	int c=0;
	for(i=0;i<j;i++){
		datV[i]=new double*[rows];
		for(k=0;k<rows;k++){
			datV[i][k]=new double[cols];
			for(l=0;l<cols;l++){
				datV[i][k][l]=conv[c];
				//cout<<datV[i][k][l]<<" ";
				c++;
			}
			//cout<<endl;
		}
		//cout<<endl<<endl;
	}
	return 0;
}


and profile data like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
normal
	-1	-1	63	-3	-1	0
	0	0	62	-3	-1	0
	-1	-1	61	-3	0	0
	-1	-1	63	-2	-1	0
	-1	-1	63	-3	-1	0
	-1	-1	63	-3	-1	0
	-1	-1	63	-3	0	0
	-1	-1	63	-3	-1	0
	-1	-1	63	-3	-1	0
	-1	-1	61	-3	0	0
	-1	-1	61	-3	0	0
	-1	-1	64	-3	-1	0
	-1	-1	64	-3	-1	0
	-1	-1	60	-3	0	0
	-1	0	64	-2	-1	0


normal
	-1	-1	63	-2	-1	0
	-1	-1	63	-3	-1	0
	-1	-1	61	-3	0	0
	0	-4	63	1	0	0
	0	-1	59	-2	0	-1
	-3	3	57	-8	-3	-1
	-1	3	70	-10	-2	-1
	0	-3	61	0	0	0
	0	-2	53	-1	-2	0
	0	-3	66	1	4	0
	-3	3	58	-10	-5	0
	-1	-1	66	-4	-2	0
	-1	-2	67	-3	-1	0
	0	1	66	-6	-3	-1
	-1	-1	59	-3	-4	0


nVal storing string characters. nVal result is:

-1-163-3-100062-3-10-1-161-300

now conv is:

-1-163-3-1000062-3-10-1-161-3000

0 values has added when nVal converted, how to remove 0 values?
Last edited on
Topic archived. No new replies allowed.