I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.
!indentation
<nolyc> indentation is optional whitespace. see also: !vowel
!vowel
<nolyc> vwls r bt s sfl s whtspc, spclly n vrbl nms. s ls: !ndnttn
!ndnttn
<nolyc> indentation is optional whitespace. see also: !vowel
Line 41 should execute only when you do found the substrings. Also, make sure that `position2>=position1'
Your loop is incorrect, use while( getline(file,text) ) instead
Suppose that text is
`the quick brown fox jumps over the lazy dog'
¿what value position1 and position2 would hold?
¿what text.erase(position1, position2); would do in that case?
//delete everything between position1 and position2
text.erase(position1, position2+1);
This is wrong. This overloaded version of string::erase takes as its first argument the index of the first character to remove and as its second argument the number of characters to remove, so: text.erase(position1, position2-position1+1) is what you should be using. Of course, you should also verify that position2 comes after position1 in the string.
You should probably also verify that both files are being opened.
Thank everybody, but i don't know how to program what ne555 said:
Suppose that text is
`the quick brown fox jumps over the lazy dog'
¿what value position1 and position2 would hold?
¿what text.erase(position1, position2); would do in that case?
You already have the right if-statements when you're finding; but you're not using them in the right way. You cannot erase if you don't have valid start and end positions. (Where are the < and > in the string ne555 gives?)
It would be better to start the second find from one past the position of the first one. The position to start with can be specified using the second parameter (which default to 0)
Also, your code (if you sort out the if-statements) will only remove one <tag> a line. You'll need another loop if you want to remove more than one per line.