Hello. today I tried using std::map and std::isalnum and I ran into a problem where I do not know how to get text input from a file , tried using string but it did not work because of invalid conversion from char to const char.
How can I input from file ?
#include <map>
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
int main()
{
char ch;
std :: ifstream tekstas;
std :: ofstream rezultatas;
tekstas.open("tekstas.txt") ;
rezultatas.open ("rez.txt");
std::map<char, int> themap;
std::string test = ch; // ---- here was text but I want to input from file (tekstas.txt)
while (tekstas.get(ch))
for (size_t i = 0; i < test.size(); ++i)
{
ch = test[i];
if (isalnum(ch))
themap[ch]++;
}
for (auto& m : themap)
rezultatas << "Raide '" << m.first << "' buvo panaudota " << m.second << " tiek kartu\n";
rezultatas.close ();
tekstas.close() ;
return 0;
}
The tekstas.txt file just input some random text , like Lorem Ipsum