Apr 13, 2013 at 3:25pm UTC
Hello everyone, I'm new in this forum and in C++.
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++.
Apr 13, 2013 at 3:46pm UTC
What is going on in:
inFile >> index;
if( yourfindname == name[index] )
Thanks for the fast reply.
Apr 13, 2013 at 6:54pm UTC
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?
*name could be a type that has operator too.
Apr 13, 2013 at 7:46pm UTC
Hmmmm.. I just read three or two tutorial, looks like I need to read all of them.
Thanks for all the help guys, well it's going to be a fun weekend huh.
Apr 14, 2013 at 10:03am UTC
just an example.
if i provide such code of this and u stil not understand
that's mean you don't have any basic on it.
i prefer u go do some experiment on it before u rush your homework
a lot code need to figure it out.
if you don't know it how to work.
u might fail in future. but of course
if have any problem u can ask us here
u try build or create a new code for yourself
and then post it here.
i will always help u then
Apr 14, 2013 at 12:38pm UTC
Alright thanks :)
Also try to use Google translator or something before you post, your english isn't at its best.
Anyways thanks to everyone for replaying, I'll start reading the tutorials next weekend.
//Topic Closed (There's no need to reply anymore)