In file i have a text. Words form line to line dont raising. Word in line separate least one space.Spaces can be at line begining and ending, can be empty lines. Count how many words can be in real number.
i need a function whitch can count words whitch can be real number.

I started like that this was first task, and now i need to count words, please help me ;/

const char Cduom[] = "Duomenys.txt";
const char Crez[] = "Rezultatai.txt";
const char Canalize[] = "Analize.txt";
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

void ApdorotiTeksta(const char dfv[], const char rfv[]);
void AnalizuotiEilute(string eil);

int main()
  ApdorotiTeksta(Cduom, Crez);

void ApdorotiTeksta(const char dfv[], const char rfv[])
  ifstream fd(dfv);
  ofstream fr(rfv);

  string E;

  while(!fd.eof()) {
    getline(fd, E);
    fr << E << endl;


void AnalizuotiEilute(string eil )
	string Zodis;
  string Skirt = " ,!?:;()\t"; 
  int zpr = 0, zpb = 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);

Recommended Answers

All 3 Replies

Dont read it line by line. Instead, read it word by word. The check if each word is a valid real number. Example:

int main(){
 ifstream fileIn("input.txt");
 string word;
 unsigned int count = 0;
 while( fileIn >> word )
    if( isRealNumber( word ) ){  //you need to implement isRealNumber

Note in the above I assume each words are separated by spaces

I dont know how to count a words, im beginer :/

Read a word fin >> word; Increment counter numwords++;

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.