ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
having rows with usually a certain fixed number of columns,
different comments marked with the start letter #, with some blank lines.
Blank lines and comment line should be ignored while reading.
The file may also contain by mistake wrong number of columns which should be corrected first as well.
Each row gives a class object and it should be saved as an element vector of class object.
For this purpose I have written a code. Everything works fine till end but while terminating the program it comes unknown problem.
Could anyone please help me in finding out mistake? I have marked the possible mistake place as c++ comments.
thank you
File to be read:
#myfile.txt
1 snp1 1.1 1
2 snp2 1.2 2
3 snp3 1.2 3
# 1
#2
It is not necessary to manually call the class destructor; this is done automatically when the object falls out of scope, and hence is destroyed. Thus remove this line of code from your main() function:
I have deleted it but it still crashes. I do not know why. If you could have a look little bit deeply??
I do not know why either. I copy/pasted the code you originally posted, removed the offending line I mentioned earlier, and compiled the program. I then created the data (text) file with the information you supplied, and then ran the program. It completed successfully. I then re-ran the program using valgrind, and it also reported that all allocated memory had been freed.
Thus barring the possibility that you changed more of your code than you are admitting to, I find it hard to believe that the code is still causing an anomaly. Perhaps you failed to recompile the code after you made a change??
I do not know why either. I copy/pasted the code you originally posted, removed the offending line I mentioned earlier, and compiled the program. I then created the data (text) file with the information you supplied, and then ran the program. It completed successfully. I then re-ran the program using valgrind, and it also reported that all allocated memory had been freed.
Thus barring the possibility that you changed more of your code than you are admitting to, I find it hard to believe that the code is still causing an anomaly. Perhaps you failed to recompile the code after you made a change??
thank you so much dwhitney67! It worked well now. Do you think I can use RAII std::tr1::shared_ptr at this case in stead of delete?
I do not see any declaration of snpVec in the code. Am I simply missing it, or does it not exist?
If snpVec were a vector of CSNP*, it would provide push_back() of the CSNP* pCSNP to build a list by appending the new pointer at the end of the list.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.