io - c++ program suddenly stopped writing to file -
i have little c++ programming experience, , wrote quick program find groups of links in long link list.
i have been using program last 2 days , worked fine (i'm guessing inefficiently, worked). stopped writing file. made new file , changed file name in program check corruption still isn't working. have identical program searching through separate link list, , program still working.
here code: i've gotten program write file checking strings while loop, instead of loop
#include <iostream> #include <fstream> #include <string> int main() { std::string string; std::string findstring; std::string line; std::ifstream infile; std::cout<<"find string: "; std::getline(std::cin, findstring, '\n'); infile.open("old.rtf"); std::ofstream returnfile("return.txt"); int = 0; std::string previousline = ""; while(a < 1) { std::getline(infile, string); while(string != previousline && string.find(findstring) != std::string::npos) { previousline = string; returnfile<<string<<"\n"; std::cout<<string<<std::endl; } } infile.close(); std::system("pause"); return 0; }
i'm compiling using g++ on mac (running mountain lion)
thanks help!
it seems issue might related infinite loop.
int = 0; std::string previousline = ""; while(a < 1) { // needs incremented in here or loop forever! }
Comments
Post a Comment