What's wrong !! I try to run this code but still showing me this in the compile :-( #include #include #include #include using namespace std; template void printmap(map < KTy, Ty >&map){ typename std:: map::iterator iterator; for(iterator p=map.begin();p!=map.end();p++){ cout << p->first<<":" <sceond< wordscount; { ifstream filestream(fileName); if(filestream.is_open()){ while (filestream.good()){ string word; filestream>> word; if(wordscount.find(word)==wordscount.end()){ wordscount[word]=1; } else{ wordscount[word]++; } } } else{ cerr << "Can't open the given file."<
What's wrong !!
I try to run this code but still showing me this in the compile :-(
#include<iostream>
#include<map>
#include<string>
#include<fstream>
using namespace std;
template <class KTy,class Ty>
void printmap(map < KTy, Ty >&map){
typename std:: map<KTy,Ty>::iterator iterator;
for(iterator p=map.begin();p!=map.end();p++){
cout << p->first<<":" <<p->sceond<<endl;
}
}
int main(void){
static const char* fileName="hitchhikersguide.txt";
map<string , unsigned int > wordscount;
{
ifstream filestream(fileName);
if(filestream.is_open()){
while (filestream.good()){
string word;
filestream>> word;
if(wordscount.find(word)==wordscount.end()){
wordscount[word]=1;
}
else{
wordscount[word]++;
}
}
}
else{
cerr << "Can't open the given file."<<endl;
return EXIT_FAILURE;
}
printmap(wordscount);
}
return EXIT_SUCCESS;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images