0

I have a simple ifstream code for reading a html file.

#include <fstream>
#include <iostream>
using namespace std;
 
int main () {
    char data[100];

    //open a file in read mode.
    ifstream infile; 
    infile.open("html9.html"); 
    while(infile >> data)
        cout << data << endl;

    infile.close();

   return 0;
}

Basically I like to search for tr tag followed by search for td tag then replace whatever inside the td tag with my own data. My html table tag is like this

            <table>
              <tr>
                <td>
                  #Title    
                </td>
                <td>
                  #Info
                </td>
                <tr>
                  <td></td>
                </tr>
              </tr>
            </table>

The html can be large file so my table tag will eventually require some searching. I need the flexibility of regex so I like to know can I use some sort of regex with istream object (istream is only which I like to use).

Sorry if I jumped right into requiring some example code and some explanation about istream and embedding regex with it but I really couldn't find any place on internet where I can also find this with example and step by step explanation.

Thanks for reading

user786
  • 3,902
  • 4
  • 40
  • 72
  • Take a look at [parsing HTML with regex](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – blackbrandt Sep 19 '21 at 12:25
  • @blackbrandt `If you have a small set of HTML pages that you want to scrape data from and then stuff into a database, regexes might work fine` basically I am just trying to create a server and I created placeholders like tags so what I am doing is simple work on limited html and always predefined html. Like replacing some html thing with my own data. So link does not apply on this question – user786 Sep 19 '21 at 12:40
  • Alternatives are also welcomed with istream – user786 Sep 19 '21 at 13:04

0 Answers0