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
done.
Please tell me about the code
closed account (o3hC5Di1)
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,
NwN
dont spam people with pms
if anyone has time and interest he/she will post here
closed account (o3hC5Di1)
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,
NwN
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>
#include<vector>
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
while(infile)
{
//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'
text_file.push_back(temp);
}

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;
break;
}
}

// not found
if(!is_found)
{
cout << target << " not found in ye' text file. ";
}

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

}

Thanks
closed account (o3hC5Di1)
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,
NwN
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.