am writing a program that will count the votes for those whom are agree and desagreed, so i would have Yes and no, now i have to have a file in wordpad, in other to import the information that was saved, to make the program to run, but i have to idea how to start...

Recommended Answers

All 3 Replies

It sounds like you are trying to use basic file io. There are two main ways to do this, one is using standard io (stdio.h) and one is using file streams (fstream.h) you can google and learn about both of these methods.

am writing a program that will count the votes for those whom are agree and desagreed, so i would have Yes and no, now i have to have a file in wordpad, in other to import the information that was saved, to make the program to run, but i have to idea how to start...

i was a program that involves reading and writing data from a file of book mark data
using Qt Creator i wrote this function to read the file.
this example might help:

void MainWindow::load_titleData()

{

    QFile booksfile("savedbooks.sbf");//file declaration
       booksfile.open(QIODevice::ReadOnly);//open file in read only mode

     QTextStream in(&booksfile);//textstream for sending data between file and program
     QString length;int w=1;
       while(length!=ui->titlelist->currentText())//this loop is putting titles into a dropbox
             {   w=w+1;
           length=in.readLine(ui->titlelist->currentText().length()+1);
              }
     QString pr;
     QString pib;
     QString dr;
             int match=0;cout<<" loop ended ";
      while(match!=2)//looking for pages read saved values
                { match=match+1;
              pr=in.readLine(ui->titlelist->currentText().length());}
      while(match!=3)//looking for pages in book saved values
             {match=match+1;
          pib=in.readLine/* .readLine reads one line from the file, call it 3 times to read 3 lines {in.readLine; in.readLine; in.readLine;} etc. there's allot more to see in the tutorial*/(ui->titlelist-> currentText().length());}
      while(match!=4)
             {match=match+1;
          dr=in.readLine(ui->titlelist->currentText().length()); }
          ui->pgsread->setValue(pr.toInt());
          ui->pgsinbook->setValue(pib.toInt());
          ui->daysreading->setValue(dr.toInt());
          QString ct=ui->titlelist->currentText();
          ct.resize(ui->titlelist->currentText().length());
          ui->title->setText(ct);
       booksfile.close();
}

the file looks like this:
beginning
jims best book----------title
67------------------------pages read
890-----------------------pages in book
9------------------------ days reading
junie b
43
78
67
jim other book
670
789
4
james book
89
245
6
goosebumps
56
78
6
sharks
43
98
5
end,

it goes:
title
pages read
pages in book
days reading

i was a program that involves reading and writing data from a file of book mark data
using Qt Creator i wrote this function to read the file.
this example might help:

void MainWindow::load_titleData()

{

    QFile booksfile("savedbooks.sbf");//file declaration
       booksfile.open(QIODevice::ReadOnly);//open file in read only mode

     QTextStream in(&booksfile);//textstream for sending data between file and program
     QString length;int w=1;
       while(length!=ui->titlelist->currentText())//this loop is putting titles into a dropbox
             {   w=w+1;
           length=in.readLine(ui->titlelist->currentText().length()+1);
              }
     QString pr;
     QString pib;
     QString dr;
             int match=0;cout<<" loop ended ";
      while(match!=2)//looking for pages read saved values
                { match=match+1;
              pr=in.readLine(ui->titlelist->currentText().length());}
      while(match!=3)//looking for pages in book saved values
             {match=match+1;
          pib=in.readLine/* .readLine reads one line from the file, call it 3 times to read 3 lines {in.readLine; in.readLine; in.readLine;} etc. there's allot more to see in the tutorial*/(ui->titlelist-> currentText().length());}
      while(match!=4)
             {match=match+1;
          dr=in.readLine(ui->titlelist->currentText().length()); }
          ui->pgsread->setValue(pr.toInt());
          ui->pgsinbook->setValue(pib.toInt());
          ui->daysreading->setValue(dr.toInt());
          QString ct=ui->titlelist->currentText();
          ct.resize(ui->titlelist->currentText().length());
          ui->title->setText(ct);
       booksfile.close();
}

the file looks like this:
beginning
jims best book----------title
67------------------------pages read
890-----------------------pages in book
9------------------------ days reading
junie b
43
78
67
jim other book
670
789
4
james book
89
245
6
goosebumps
56
78
6
sharks
43
98
5
end,

it goes:
title
pages read
pages in book
days reading

the first sentence is supposed to say
i was writing a program that involves reading and writing data from a file of book mark data. not, I was a program that involves reading and writing data from a file of book mark data. I had to fix my mistake it looked very bad.

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.