Extracting specific data from file

Please someone help me how to read specific data from a file, like email adresses, URL's, integer type data, character type data and other.
please someone help me,, i am new to C++
read from file to string
search for key words in the string
Please tell me about the code
Hi there,

This link: http://cplusplus.com/doc/tutorial/files/ should get you going.

Please do let us know if you have any further questions.

All the best,
dont spam people with pms
if anyone has time and interest he/she will post here
KerryKhan wrote:
Please tell me about the code

Please make an attempt yourself first and share your code with us if you encounter any problems.

All the best,
Ok thanks,, i m trying
This is my code but it have errors, i have tried mybest to fix it but failed, please somebody help me

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
string target;
int pos = 0;
bool is_found = false;
ifstream infile;

//make a custom made container that can hold a line of text
struct line_struct
string line_number;
string two_letters;
string a_number;

//now make a bunch of containers
vector<line_struct> text_file;

//make a temporary container
line_struct temp;

//read the text file
//load the temporary container
//read in the text file, 'word at a time'
infile >> temp.line_number;
infile >> temp.two_letters;
infile >> temp.a_number;

//load the text_file vector with a 'line of text'

cout << "Enter something ye' wish to find in ye' text file: ";
cin >> target;

for(int i=0, size=text_file.size(); i<size; i++)
if(target == text_file[i].line_number || target == text_file[i].two_letters || target == text_file[i].a_number)
pos = i;
is_found = true;

// not found
cout << target << " not found in ye' text file. ";

else //found
cout << target << " found in line " << pos << " of ye' text file. ";


Which errors are you getting?
Also, please wrap your code in [code][/code] tags, that makes it more readable.

Did you write that code yourself by the way, or did you buy it off a pirate? ;)

All the best,
i have got help from net,,
there is an error in the lines
vector<line_struct> text_file;
if(target == text_file[i].line_number || target == text_file[i].two_letters || target == text_file[i].a_number)
Last edited on
Topic archived. No new replies allowed.