-
C++ /strings
I need help!
I'm writing a program to up date a c++ text file which enables the user to be interative with the program by entering different words in the text file. I'm having trouble finding what library function is used to find a specfic character in the text file.
My task is to read the text file word by word looking for a particular character ie,. The [noun] is broken..etc. It enables the user to add their own noun. I then need to write each word to a output file.
-
Registered User
if the file is not too big, i would read the whole thing into memory then generate a new file when i was done
-
I did intend to do that but what functions do i use to identify my character '[' or string [noun] in the text in order for the user to replace [noun] with their input
-
You can recognize a whole word, for example replace every instance of the word red, by comparing strings. However, there are several ways to compare strings depending on whether you use c_style strings (aka null terminated char arrays) or some sort of string class. If you use c_style strings you need to use one of the strcmp() functions in string.h (or cstring depending on your compiler). You can use == if you use the string class in STL. You can find each [ by comparing char by char. If you use the string class in STL there is a group of find() functions that you can use as well.
Popular pages
Recent additions