I've searched about my question but I didn't managed to understand the solution, that's why I created this topic. Here's my question:
I want to code a program to find a word in a file, ex:.
There's a file called db.txt and inside there are names.
I want the program to searched the file for a user provided name. The user opens the program, types a name and the program searched the file for that name.
If the name is found the program displays something like "name found" if it's not found the program adds the name to the file (to the last line).
(Each line of the file has one and only one name)
That's all, thanks for reading and please help.
Also try to explain the code with commentaries because as I said I'm new to C++.
inFile is of type std::ifstream. Look at its documentation on this site, particularly operator>>.
The code is incomplete, because it does not declare index, name or yourfindname. However, we see apparent constructs:
if ( expr ) -- conditional test that evaluates expr and uses the result as a boolean. expr1 == expr2 -- equality comparison between two expressions.
name[index] -- assuming index is int and name is array or pointer*, dereference 'name' to retrieve one value.
Have you read the tutorials that exist on this site?