Im a beginner to c++
after looking over this code you will be able to tell
the outfile code seems to work fine no errors
but any feedback will be nice
the infile code is the one i have problems with
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
string name;
string address;
string number;
ofstream outfile;
outfile.open("white.txt", ofstream::out | ofstream::app);
do
{
cout << " Upper Case 'Q' to Quit Or" << endl;
cout << " Enter persons full name : ";
getline(cin,name);
if ( name == "Q" )
break;
cout << "\n Enter persons address : ";
getline(cin,address);
cout << "\n Enter persons phone number : ";
getline(cin,number);
cout << address << " " << name << " " << number << endl;
outfile << name << endl;
outfile << address << endl;
outfile << number << endl;
}
while ( name != "Q" );
outfile.close();
return 0;
}
I cant seem to figure out a way to find() a string in the file and then display the name, address, and number
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
const int size = 10;
int main()
{
string line, name;
char file[size];
ifstream infile;
cout << " enter file name :";
cin.getline(file,size);
infile.open(file);
if(!infile.is_open())
{
cout << " could not open file" << file << endl;
cout << " program Terminating....\n";
exit(EXIT_FAILURE);
}
cout << " enter name of person";
cin >> name;
if(infile)
{
while ( getline ( infile , line ))
{
line.find(name);
if ( line == name )
{
cout << line;
}
}
}
infile.close();
return 0;
}
this only will find the name typed in and display that name
if(infile)
{
while ( getline ( infile , line ))
{
line.find(name);
if ( line == name )
{
cout << line;
}
}
}
any help would be great!!!