Hey, so im creating a work example for school and right now i'm working on an "address book" sort of. I have three options the user can select add, view, and delete contacts. I want the "view" option to be able to search for first and last names inside of a text file and view them. This whole project is inside of a console and keyboard controlled, meaning that you physically type in either "add" "view" or "delete". So basically, how do i narrow down search results by first or last names then select them and view their phone number?

Have you already written the delete function? View would be very similar.

How to do them will depend on how you designed the text file. There are as many ways to do that as there are programmers to program it.

I'm talking about creating a seperate file for each contact, putting all the required information inside the txt file then inside the program searching for the file by First and last name of the contact, then having 3 of the closest matches on the screen where the user can hit either 1 2 or 3 to select and finally view.

If i'm just rambling on and making no sense, sorry.

Unless I completely misinterpret you, no, you are making sense. What doesn't make sense is creating a file for each person. If you have 1000 people in your contact list, you're going to have 1000 files. This will make your program slow and use a lot of system (disk) resources.

You'd be better off making one file with all the contacts in it -- one contact per line would be easiest.

Unless I completely misinterpret you, no, you are making sense. What doesn't make sense is creating a file for each person. If you have 1000 people in your contact list, you're going to have 1000 files. This will make your program slow and use a lot of system (disk) resources.

You'd be better off making one file with all the contacts in it -- one contact per line would be easiest.

Alright, so the format would be to use one text file for all the contacts. But how in C++ be able to search the .txt file? Like when you open a contact list on your phone and type in a name it narrows down your search result? Thanks

Open the text file
Read the text file into your structure
Search the structure
Display what you need.

The key is read. The program can only use data it's read. Without reading, the program has no information.

Open the text file
Read the text file into your structure
Search the structure
Display what you need.

The key is read. The program can only use data it's read. Without reading, the program has no information.

Thanks! I got it working. I wrote up a quick rough program and it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.