Re: Text reading and writing
Sorry I forgot to mention what was happening at execution. I execute from the cmd prompt and a window pops up saying that my program: "text_parser.exe" needs to close. If that helps you at all...
Re: Text reading and writing
1. Edit your OP adding Code tags around code snippet.
2. Debug your code (use F5 to start debugger) and then go on line by line (F10) to see what happens
Re: Text reading and writing
You have ...
Code:
char busNum[] = "";
// then you do the folllowing :
line.copy(busNum,secondMarkPos - (firstMarkPos + 1),firstMarkPos + 1);
busNum is not large enough to hold any characters. Why not just
use std::substr() and place into a std::string ?
Re: Text reading and writing
Philip -
Thanks for your help. Perhaps that is a good idea. That part of the code is meant to grab the number associated with a power bus (I'm an intern working for a power distribution company) by reading through a Report File generated by some in-house software. I took a look at the format of this report and noticed that the bus number always appeared between the character ']' and the word 'AREA'. My intention with this code was to scan a line from the report file into memory and have the computer run through it looking for these characters in the correct order. Since they don't occur on other lines paired together like the lines that contain the bus number, I could safely have the computer ignore the lines where only one or neither of these 'markers' occur. When both markers are found i wanted the program to grab the string in between the two location of the markers and dump it into a char array and strip away the white space and throw the remaining characters into a file, to which the program would append some other numbers i wanted to grab from the report as well, but for now, i'm just trying to tackle grabbing the bus numbers. As to your suggestion: If i loaded the string in between ']' and 'AREA' using std::substr (from the example in my OP this string would read: "_77904_" where the underscores represent whitespace) could i remove that whitespace?
Again, thanks for all your help!
Re: Text reading and writing
You can remove leading and trailing whitespaces using a combination
of string::erase and string::find_first_not_of (leading) or string::find_last_not_of
(for trailing).
Since you are going to want numbers ... you might consider using stringstream ...
Code:
string s; // which contains the substr()
int value;
stringstream ss(s);
ss >> value;
// and in the second part ...
float f1,f2;
stringstream ssf(s);
ssf >> f1 >> f2;
Re: Text reading and writing
Thanks a lot for your help Philip! I think i figured it out.