c++ - Filter input received by getline -


#include <iostream> #include <string> #include <cstring> #include <fstream> using namespace std;  int main() {  string firstfile, secondfile, temp;  ifstream infile; ofstream outfile;  cout << "enter name of input file" << endl; cin >> firstfile;  cout << "enter name of output file" << endl; cin >> secondfile;  infile.open(firstfile.c_str()); outfile.open(secondfile.c_str());  while(infile.good()) {        getline(infile, temp, ' ');          if (   temp.substr(0,4) != "-----"             && temp.substr(0,5) != "header"              && temp.substr(0,5) != "subid#"             && temp.substr(0,5) != "report"             && temp.substr(0,3) != "date"             && temp             != ""             && temp             != "")          {             outfile << temp;         } }  infile.close(); outfile.close();  return 0;    } 

hi all. i'm attempting output lines text file not meet criteria in control structure -- i.e. no blank lines, no symbols, etc. however, when run code outputs everything, not taking consideration specifc requirements. if tell me i'm doing wrong appreciated.

if @ reference such this see second argument substr the number of character not ending position.

this means e.g. temp.substr(0,5) might return "heade" indeed not equal "header". means non-empty string output.

also note right now, don't read lines words separate input on space.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -