Need a Way to Find/Read a Line From a .txt File

I plan to have my program to get the user's first name, middle initial, last name, age, and other varied things later on. Then once they have been inputted, save them to a .txt file. I mainly know how to write to a .txt file, but I have searched for hours for a way to search a .txt file for a one-line string. Either, none of them work for my situation, they don't work at all, or I don't understand them. If anyone could give me a run-down on different methods of doing so, I would be quite grateful.

The bottom function of is where I plan to do the finding/reading from a separate file that has each structured as followed:
[firstName]space[middleInit]space[lastName]space[fileName(aka the initials)]

Here's what code I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cstdio>
using namespace std;

void checkName(char* firstName, char middleInit, char* lastName, char* fileName, bool &sameName);

int main()
{
	//Declare Variables
	char firstName[11] = {};
	char middleInit;
	char lastName[11] = {};
	char fileName[5] = {};
	int userAge;
	bool sameName = false;
	ofstream fileout1;
	
        //Get user input
	cout << "Please enter your..." << endl;
	cout << "First name:  ";
	cin >> firstName;
	firstName[0] = toupper(firstName[0]);
	cout << "Middle initial:  ";
	cin >> middleInit;
	middleInit = toupper(middleInit);
	cout << "Last Name:  ";
	cin >> lastName;
	lastName[0] = toupper(lastName[0]);
	cout << "Age:  ";
	cin >> userAge;

	//Sets the corresponding initial to the correct letter from the names
	fileName[0] = firstName[0];
	fileName[1] = middleInit;
	fileName[2] = lastName[0];
	
	//Check Names file for the 
	checkName(firstName, middleInit, lastName, fileName, sameName);
	
	system("pause");
	return 0;
}//End of main function

//Function definitions
//checkName function
void checkName(char* firstName, char middleInit, char* lastName, char* fileName, bool &sameName)
{
	char nameLine[30] = {}
	ifstream fileout2;

	//Opens Names file
	fileout2.open("Names.txt");

	//Searches for name info line
}


Thanks!
Topic archived. No new replies allowed.