I am doing a dictionary program. Where i am trying to read the data from the text file and after it reads it it sorts it by the word and print the sorted list. as well as if i was to search for a word, or add a new word to the list. how should i do it.?
#include <iostream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <vector>
#include <iomanip>
#include <conio.h>
#include "word.h"
using namespace std;
int parseLoadNSort()
{
vector<word> wordInfo;
string Name;
string Definition;
string prtspeech;
ifstream readFile1("/Users/New/Desktop/wb1913_samp260.txt");
string line((istreambuf_iterator<char>(readFile1)),
istreambuf_iterator<char>());
stringstream iss(line); cout << "iss(line)" << endl;
while(!iss.eof())
{
for(int j=0; j<wordInfo.size()-1; j++)
{
for(int i=0; i<wordInfo.size()-1; i++)
if(wordInfo[i].getName() > wordInfo[i+1].getName())
swap(wordInfo[i].getName(), wordInfo[i+1].getName());
getline(iss, Name,'\t');
cout << "name - " << Name << endl;
if (Name == "")
break;
getline(iss, prtspeech, '.');
cout << "prtspeech - " << prtspeech << endl;
getline(iss, Definition, '\n');
cout << "definition - " << Definition << endl;
getch();
word splitedColumns(Name, prtspeech, Definition);
wordInfo.push_back(splitedColumns);
}
cout << "Info reterived from file" << endl;
getch();
return 1;
}
int main()
{
parseLoadNSort();
}
Aucun commentaire:
Enregistrer un commentaire