My first project using ASCII file I/O

I plan on doing a software that reads a text file and then converts anything that consists only of + P K G 1 2 3 4 5 6 7 8 9 (like this: 236P+K, not the P & K of Poker) into an html tag that points to a picture.

I thought it would be best if I let it read the complete text word for word and let it check if the word contains any other char then the ones listed.
If it contains anything else it won't convert. If it contains only the chars listed it converts them.

I've learned some of the ASCII I/O stuff and I'm browsing the Fstream reference, but I can't really find which ones I have to use to realize it.
Can I have some tips plz ^-^
You might be better off using the 'sed' utility. I assume that there is some relationship to the text to find and the name of the image file?

 
sed -e 's/([1-9+PKG]*)/\<img src="images/\1\.jpg" alt=""\>/g' original.html > output.html

This takes your string (like "236P+K") and replaces it with a string like
<img src="images/236P+K.jpg" alt="">


If you really must use C++, the pseudocode would look something like this:
1
2
3
4
5
6
7
8
9
string line;
while (getline( cin, line ))
{
  if (find_pattern_in_line( line ))
  {
    modify_line( line )
  }
  cout << line << endl;
}

The find and modify stuff is the hard part. I recommend you check out the Boost Regular Expression Library (find it at <http://www.boost.org/libs/regex/doc/index.html>).

or if you have the GCC you can use the GNU Regular Expression Library (find it at <http://www.delorie.com/gnu/docs/regex/regex_toc.html>).


And, if you really won't use regular expressions, you can roll your own search function using the C++ std::string class search functions. This site has excellent documentation for that.


Hope this helps.
Topic archived. No new replies allowed.