![]() |
| ||
| Array and File Help I am writing this program that reads in lines from a txt file into an array. Some lines start with a number and some don't. Problem is that I need help on how to display the lines that don't start with a number. Examples of txt file: Students Code I have so far: getline(inFile,row); //read each line in fileI just don't know how to get each line that doesn't start with a number from the array and display it. I have tried something like the below, but I think that it doesn't work since each line that has a number, stores whatever follows that number. for (i = 0; i < num; i++) |
| ||
| Re: Array and File Help Quote:
To print out all the lines, I'd suggest a simple loop: for (int i=0; i<num; i++) Now all you need to do is remove line numbers on the lines that do happen to have numbers. For removing the number, I'd suggest using string::find_first_not_of with a single space as an argument. Now check that the character found is not a number with isalpha, and then you can proceed either by removing the number if it is one, or simply leaving the string as-is. Or did I totally misunderstand what you're trying to do? |
| All times are GMT -4. The time now is 8:01 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC