![]() |
need help in vectors
hi I am trying to read text from text file and put it in a vector v1. then I copy text from v1 to another vector v2.
my text file is in this format Code:
studentNamehere is my code so far Code:
#include <iostream>Code:
Debug assertion failed |
Re: need help in vectors
Hello. First thing, the error you get is from the copy() function you use to make v2 equal to v1. The simple way to fix this is to remove that and instead use an equals sign:
v2 = v1; That gets rid of the error. Now, for the lines of text you do not want to display, I could only think of one way to do so, and there may be a better way, but this does work. All you would have to do is have an if statement under the line: getline(in, line); This if statement would pretty much just say, if line contains "studentName", "FatherName", or "separator", continue (literally, use a continue statement). Else, push line onto vector. To me, that is the simplest way to achieve the solution you want. Other than just removing studentName, FatherName, and separator from the text file. But I assume you can't do that. Anyway, I hope this helped. Oh, and you might want to close the text file at the end of your code also. I'm not sure if you just hadn't gotten to that yet, but it wasn't in your code, so I thought I'd mention it. Kurt Bales UAT Student |
| All times are GMT +5.5. The time now is 10:09. |