Witam!
Wyrzuca mi dosc dziwny blad w 16 i 17 linicje. Tutaj wrzucam kod:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <map>
using namespace std;
template <class KTy, class Ty>
void PrintMap(map<KTy, Ty> map)
{
typedef map<KTy, Ty>::iterator it;
for (iterator p = map.begin(); p != map.end(); p++)
cout << p->first << ": " << p->second << endl;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(void)
{
string fileName;
char c;
int array_size = 1024;
char *array = new char[array_size];
int poss = 0,
itype = 1,
i = 0,
count = 0;
// open the file
cout << "Podaj nazwe pliku, bez rozszerzenia.\n"
"Rozszerzenie z jakiego korzysta program to *.txt " << endl;
cout << "Nazwa pliku: ";
cin >> fileName;
fileName = fileName + ".txt";
ifstream inFile;
inFile.open(fileName.c_str());
if (inFile.is_open()){
while (!inFile.eof() && poss < array_size){
//reading one character from file to array
inFile.get(array[poss]);
++poss;
}
//placing character array terminating character
array[poss-1] = '\0';
system("cls");
cout << "Plik zostal otwarty prawidlowo, co dalej chcesz z nim zrobic?\n";
while(itype != 0){
cout << "[1] Pokaz zawartosc pliku\n";
cout << "[2] Ile znakow jest w pliku?\n";
cout << "[3] Ile jest wyrazow w pliku?\n";
cout << "[4] Posortuj wyrazy alfabetycznie (z powtorzeniami)\n";
cout << "[5] Ile razy wystepuje dany wyraz w pliku\n";
cout << "[0] Wyjdz\n";
cin >> itype;
switch(itype){
// show text
case 1:{
system("cls");
for (int i = 0; array[i] != '\0'; ++i){
cout << array[i];
}
cout << endl << endl << endl << endl;
break;
}
// count of characters
case 2:{
system("cls");
cout << string(array).length();
cout << endl << endl << endl << endl;
break;
}
// count of words
case 3:{
system("cls");
string text;
inFile >> text;
map<string, unsigned int> wordsCount;
if (wordsCount.find(text) == wordsCount.end()) // Then we've encountered the word for a first time.
wordsCount[text] = 1; // Initialize it to 1.
else // Then we've already seen it before..
wordsCount[text]++; // Just increment it.
PrintMap(wordsCount);
cout << endl << endl << endl << endl;
break;
}
// sort
case 4:{
system("cls");
break;
}
// count of how many times word shows
case 5:{
system("cls");
break;
}
default:{
system("cls");
break;
}
}
}; //while
system("cls");
cout << "Dziekujemy za skorzystanie z programu. Zapraszamy ponownie.\n";
} // end of if - file is open
// if can't open the file
else{
system("cls");
cout << "Nie mozna otworzyc pliku. Sprawdz nazwe i wroc ponownie.\n";
}
inFile.close();
return 0;
}
Prosze o pomoc. Pozdrawiam!