Please anyone, Am having problems reading all lines of my txt file.
below is the function i wrote to read the data in the file and search thru them. but it appears to read just only the first line.. please anyone.
int stop_tag(string f_name, string u_file,string file_put)
{
ofstream f_out;
f_out.open(file_put, ios::app);
f_out<<"Location of STOP condons TAG found at Locations :" <<endl;
ifstream yourfile (f_name);
size_t search;
if (yourfile.is_open())
{
while ( yourfile.good() )
{
getline (yourfile,u_file);
for ( int p = 1; p < u_file.length(); p++)
{
I had to work and work to get your code to compile, This is formatted, and complies. I don't suggest you use it, but did you try to take out the break statement on line 21 yet ?
If the break is not at fault, it may be the logic.
cout your values for search, u_file.length, p, and any I missed to see if the values are what you expected. I can't compile your code as is and don't know what the input is so can't really help there.
thanks alot, but your coding only still shows the first line alone. my file has different lines of strings. what i want to do is search for all lines to get the positions of a particular string "TAG" as above. but all it seem to do is only search in the first line alone. i hope this gives you more understanding of what am trying to do.. i need help seriously.
My program shows all lines, so maybe it's your data. How about posting the first 3-4 lines of your data.
*Edit*
This was my test file and what the output should look like with the above program.
C:\Temp>type out.txt
3 6
3.9 4.5
3.1 4.2 5.1
1.2 2.3 3.1 4.2
A
ABC
AB CD EF
G H I J
C:\Temp>testxxx
3 6
3.9 4.5
3.1 4.2 5.1
1.2 2.3 3.1 4.2
A
ABC
AB CD EF
G H I J