Simple c++ exercise to strings and list. The program is explained at:
main page
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- using namespace std;
- list<string> or_q;
- int main ()
- {
- or_q.push_back("IP_");
- or_q.push_back("VHDL_IP_Stack1111");
- if(or_q.empty()) {
- cout<<"error and q is empty" << endl;
- return 1;
- }
- list<string>::iterator it;
- string st;
- fstream infile;
- infile.open ("1", ios::in);
- while(getline(infile,st))
- {
- getline(infile,st);
- for(it=or_q.begin(); it != or_q.end(); it++) {
- string::size_type pos = st.find(*it);
- if(pos != string::npos) {
- cout << pos << " match " << *it << " " << st << endl;
- }
- }
- }
- infile.close();
- }
An example for string split into fields:
cpp split
|