Hello, I have a bit of a problem here: I am trying to make the search find the positions of a string in the text file. The .txt file is very large and the string comes up multiple times, so I need a way to delete part of the txt file up to the point I see the first occurence of the word
Here is my code: -
#include <iostream>
-
#include <iomanip>
-
#include <fstream>
-
#include <string>
-
#include "sourcetxt.h"
-
-
using namespace std;
-
-
const string prntpath = "C:\\data.txt";
-
-
class txtfiles
-
{
-
private:
-
CURLcode crl;
-
int offset;
-
string url;
-
string frgdate;
-
string search;
-
ifstream infile;
-
public:
-
txtfiles() //constructor for url
-
{
-
cout << "Enter the URL:";
-
cin >> url;
-
-
crl = copy(url, prntpath);
-
};
-
-
const int& organize()
-
{
-
infile.open(prntpath);
-
-
if (infile.fail())
-
{
-
cout << "Error: Could Not Open Input File!";
-
return 1;
-
}
-
-
cout << "Successfully Opened Input File." << endl;
-
-
search = ", 200";
-
while (infile.good())
-
{
-
while (!infile.eof())
-
{
-
getline(infile, frgdate);
-
if ((offset = frgdate.find(search, 0)) != string::npos)
-
{
-
cout << "found '" << search << "' @ offset " << offset << endl;
-
return 0;
-
}
-
}
-
}
-
};
-
};
-
I currently need help with 2 things: 1. Getting position of the string in the text file 2. Erasing the previous part of the text file
If you have experience, please help me.
1 6838
You can use infile.tellg() to find out the position of the beginning of each line -- use it as the last statement in the loop so you'll know the position before each call to getline. Then adjust that value by the position of your search string in the line. http://www.cplusplus.com/reference/i...istream/tellg/
By the way, your code doesn't seem to allow for the possibility that the search string might overlap the end of a line. If that's a possibility, you can save the last few (search string length - 1) characters of each line to search with the next line.
Also, instead of - while (infile.good())
-
{
-
while (!infile.eof())
-
{
-
getline(infile, frgdate);
-
// ...
-
why not - while (getline(infile, frgdate)
-
{
-
// ...
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Julie |
last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB)
for a given string.
The files are unindexed and unsorted, and for the purposes of my immediate
requirements, can't be indexed/sorted.
I don't want to load the entire file into physical memory, memory-mapped files
are ok (and preferred). Speed/performance is a requirement -- the target is to
locate the string in 10 seconds or less for a 100 MB file. The...
|
by: thorpk |
last post by:
I have an access database that i have added a pop up calendar to, the
Table information for the Date Reported field is
Date/Time
format short date,
input mask is 00/00/0000.
i have created a combo box on the form and have bound the control to
the Date Reported field. I have placed the calendar control on the
form and set the Visible property to no.
The following code has bee added to the Mouse Down Event of the Date
|
by: fh217 |
last post by:
Hi,
Is there a way in Access to retrieve data in a specific area of a text file?
The data ( a 6 character date in YYMMDD format ) always resides on the
second line in positions 11 to 16. Thank you in advance for you help.
|
by: ogo796 |
last post by:
Hi everyone i want to search the text file,using pregmatch() but it seems like
it dose't serch.maybe my serching pattern is not right.look at the following code.
Myfile look like this
--------------------------------
file : (49/06/01) simon 13;
file : (68/05/01) John 17 ;
i want to serch simon 13 on the text file.
can anyone help me with pregmatch patterns.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |