How to remove the last character when reading a line?
I'm reading a .txt data file line by line and copying it into another .txt file and it keeps adding "\"that at the end of every line.
How can I get rid of it?!!!!
That shouldn't be happening. It's like some problem with your code.
Hmmm....... here's my code.... don't think it's wrong..... :/
Btw, I add data (value[i]) after each end of line.
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
|
//while loop to extract data from .txt file and calculate pixel degrees
while(i < end_data && getline(datain, line1))
{
istringstream datstream(line1, istringstream::in);
datstream >> dum1[0] >> dum1[1] >> dum1[2] >> dum1[3] >> dum1[4] >> dum1[5] ;
datastore[i][0] = strtod(dum1[0].c_str(), &pEnd); //lat
datastore[i][1] = strtod(dum1[1].c_str(), &pEnd); //long
latpix[i] = (laurentides.lat-datastore[i][0])/(laurentides.x_pixsize);
lonpix[i] = (datastore[i][1]- laurentides.lon)/(laurentides.y_pixsize );
//offset here calculates the number of pixels that the data occupies in the actual binary file and points to it
offset = latpix[i]*laurentides.numsamples+lonpix[i];
//here were getting the size of the data in memory
offset = offset*sizeof(float); //float
// cout<<"reading file at "<< offset <<endl;
is.seekg (offset, ios::beg);
is.read ((char *) &value[i], sizeof(double)); //double
//cout <<"THIS IS FSEEK VALUE: " << value[i] << endl;
asciiwrite << dum1[0] << " "
<< dum1[1] << " "
<< dum1[2] << " "
<< dum1[3] << " "
<< dum1[4] << " "
<< dum1[5] << " "
<< value[i] << endl;
i++;
}
| |
output:
1 2 3 4 5
|
46.710014 -71.259471 44.489597 -1.485428 -0.059414 6.298206\ -26.1162
46.710042 -71.259701 44.635906 -1.841427 -0.475201 3.920475\ -31.8444
46.710211 -71.259656 44.435902 -1.663170 -0.178196 8.078243\ -23.5934
46.710182 -71.259423 44.253120 -1.307129 0.297077 9.149914\ -16.6559
46.710153 -71.259189 44.764111 -1.723507 -0.118870 7.547733\ -21.2177
| |
Last edited on
Topic archived. No new replies allowed.