6 Replies - 298 Views - Last Post: 06 July 2013 - 05:58 PM Rate Topic: -----

#1 younes++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-July 13

drop a character from a text file

Posted 06 July 2013 - 03:08 PM

Hi,
I'd like to remove the character % from a text file using c++
Thanks
Younes
Is This A Good Question/Topic? 0
  • +

Replies To: drop a character from a text file

#2 ConciselyVerbose  Icon User is offline

  • D.I.C Regular

Reputation: 90
  • View blog
  • Posts: 315
  • Joined: 05-July 13

Re: drop a character from a text file

Posted 06 July 2013 - 03:10 PM

You're going to have to give more detail than that in order for someone to help you. What you have so far and a more specific description of what you are trying to do would be a good start.
Was This Post Helpful? 0
  • +
  • -

#3 younes++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-July 13

Re: drop a character from a text file

Posted 06 July 2013 - 03:14 PM

I send u the code
I want to use the file surf_db.txt. but it contains some strings starting with %. I want to drop them from the file surf_db.txt.

Mat clustering(){
int vari;
ifstream ifs( "surf_db.txt" );
string temp;
char separateur=' ';
vector<string> vecteur;
Mat matrixe;
line_size=0;
colomn_size=0;
while( getline( ifs, temp))

{
vecteur.clear();

string::size_type stTemp = temp.find(separateur);
while(stTemp != string::npos)
{
colomn_size++ ;
if(temp.substr(0, stTemp)!=temp.substr(0, stTemp))
vari=0;
else
vari=1;

if(vari==1)
vecteur.push_back(temp.substr(0, stTemp)); // add a string to the vector 
temp = temp.substr(stTemp + 1);
stTemp = temp.find(separateur);

}

matrixe.push_back(vecteur);
line_size++;

}
return matrixe;
}


thanks

This post has been edited by jimblumberg: 06 July 2013 - 03:30 PM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,562
  • Joined: 25-December 09

Re: drop a character from a text file

Posted 06 July 2013 - 03:31 PM

Please post the smallest possible complete program (inside code tags)

:code:

Along with a sample of any input or input file.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 younes++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-July 13

Re: drop a character from a text file

Posted 06 July 2013 - 04:37 PM

This is a sample of the code:

 while(stTemp != string::npos)
17
{
18
colomn_size++ ;
19
if(temp.substr(0, stTemp)!=temp.substr(0, stTemp))
20
vari=0;
21
else
22
vari=1;
23
 
24
if(vari==1)
25
vecteur.push_back(temp.substr(0, stTemp)); // add a string to the vector
26
temp = temp.substr(stTemp + 1);
27
stTemp = temp.find(separateur);
28
 
29
}
 


This code reads a text file. I give you a sample:

, 255, 255, 255, 0, 131, 92, 247, 227, 3, 1, 50, 244, 255, 190, 95, 135, 50, 113, 248, 255, 255, 47, 209, 252, 255, 62, 27, 76, 205, 207]
192.65 28.9043 [255, 255, 255, 55, 0, 0, 0, 64, 224, 195, 7, 63, 240, 199, 255, 255, 255, 255, 252, 49, 14, 192, 0, 71, 0, 128, 25, 35, 8, 3, 4, 96, 0, 255, 255, 255, 255, 29, 194, 24, 231, 152, 131, 16, 8, 225, 255, 0, 0, 96, 48, 49, 153, 252, 255, 255, 129, 72, 100, 38, 27, 204, 204, 207]
166 31 [176, 251, 255, 255, 243, 195, 3, 0, 128, 134, 29, 238, 112, 199, 63, 254, 255, 255, 253, 115, 14, 195, 0, 4, 0, 0, 224, 255, 255, 255, 119, 143, 25, 108, 252, 255, 255, 255, 243, 28, 196, 0, 3, 0, 0, 0, 36, 143, 207, 255, 255, 206, 226, 253, 255, 247, 217, 124, 97, 32, 16, 12, 28, 8]


I want to drop the character [.

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,116
  • Joined: 05-May 12

Re: drop a character from a text file

Posted 06 July 2013 - 05:13 PM

So I'll ask the silly question: Why are you trying to parse the file? If the your objective is merely to ignore a character, just read the file one character at a time. If the character should not be ignored, output the character to another file. If it should be ignored move on to the next file.

Or do you also need the file parsing, as well as ignoring the character?
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1345
  • View blog
  • Posts: 4,631
  • Joined: 19-February 09

Re: drop a character from a text file

Posted 06 July 2013 - 05:58 PM

View Postyounes++, on 06 July 2013 - 11:14 PM, said:

I want to use the file surf_db.txt. but it contains some strings starting with %. I want to drop them from the file surf_db.txt.


Perhaps you could start with finding the character %. Is there a space before it? Could it be a tab?

string remark(" %");

string::size_type position = temp.find(remark);




Is the % is at a start of a line?

'

This post has been edited by #define: 06 July 2013 - 06:00 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1