So I have to get a working program for analyzing text, picking up words that has got 2 symbols and which are numbers and if their sum is not more than 9 i has to delete them.

I'm about to be done with reading and outputing text file. Theres also 3rd file where I return word, where it begins and its sum. Thing is if I have lets say 3 words that meets my requirements in a single row(word of 2 numbers, like 12 asdasdas 14 adsgeter 18) it returns only last one from that row (that would be 18). How do I make it so it returns all of them? (that would be AnalizuotiEilute function which means AnalyzeRow)

thats the code for all of them

#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
//----------------------------------------------------------------------------
const char Cduom[] = "Duomenys.txt";
const char Crez[] = "Rezultatai.txt";
const char Canalize[] = "Analize.txt";
//----------------------------------------------------------------------------
void ApdorotiTeksta(const char dfv[], const char rfv[], const char afv[]);
void AnalizuotiEilute(string eil, string & DviejuSkaitmenu, int & DviejuPradzia,
					  unsigned int & DviejuSuma);
void RedaguotiEilute(string &eil, int DviejuPradzia, int DviejuSuma);

int main()
{
	ApdorotiTeksta(Cduom, Crez, Canalize);
}
//----------------------------------------------------------------------------
void ApdorotiTeksta(const char dfv[], const char rfv[], const char afv[])
{
string DviejuSkaitmenu;
int DviejuPradzia;
unsigned int DviejuSuma;
ifstream fd(dfv);
ofstream fr(rfv);
ofstream fa(afv);
string E;
fa << "------------------------------------------\n";
fa << "| Žodis iš 2 skaitmenų | Pradžia |  Suma |\n";
fa << "------------------------------------------\n";
while(!fd.eof()) {
	getline (fd, E);
	AnalizuotiEilute(E, DviejuSkaitmenu, DviejuPradzia, DviejuSuma);
	if(DviejuSuma > 0) {
		fa << "| " << left << setw(20) << DviejuSkaitmenu << " | "
        << right << setw(7) << DviejuPradzia;
     fa << " | " << setw(5) << DviejuSuma << " |\n";
	 RedaguotiEilute(E, DviejuPradzia, DviejuSuma);
	}
	fr << E << endl;
}
fa << "------------------------------------------\n";
fd.close();
fd.close();
fa.close();
}
//----------------------------------------------------------------------------
//dfv - data file
//rfv - rezults file
//afv - analyzis file
void AnalizuotiEilute(string eil, string & DviejuSkaitmenu, int & DviejuPradzia, unsigned int & DviejuSuma)
{
  string Skirt = " .,!?:;()\t"; // skirtukai tarp žodžių
  string Skaiciai = "0123456789";
  string Zodis;
  int zpr = 0, zpb = 0;
  int skaiciukai[2];
  char skirstymas[2];
  DviejuSkaitmenu = "";
  DviejuPradzia = 0; DviejuSuma = 0;
 	while ((zpr = eil.find_first_not_of(Skirt, zpb)) != string::npos) 
	{
		zpb = eil.find_first_of(Skirt, zpr);
		Zodis = eil.substr(zpr, zpb - zpr);
		if(Zodis.length()==2 && !Zodis.find_first_of(Skaiciai,0))
		{
			DviejuSkaitmenu = Zodis; // it returns only that single last word from single row
			DviejuPradzia = zpr; // returns where the number starts
			skirstymas[0]=Zodis[0];
			skirstymas[1]=Zodis[1];
			char sk1=skirstymas[0];
			char sk2=skirstymas[1];
			skaiciukai[0]=atoi(&sk1);
			skaiciukai[1]=atoi(&sk2);
			DviejuSuma = skaiciukai[0]+skaiciukai[1]; // returns sum
		}

	}
}
//----------------------------------------------------------------------------

Will this help?

C++ tokens:

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main()
{
   string line = " some tokens and a  few 2349582346 2435  555 32 2 2 2 numb3r5";
   stringstream ss(line);
   vector<string> tokens;
   string temp;
   while( ss >> temp )
      tokens.push_back(temp);
   for(vector<string>::iterator it = tokens.begin(); it != tokens.end(); ++it)
      cout << *it << endl;
}

Err I don't actually get it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.