How to read from file (const problem)

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 ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #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
Last edited on
1
2
3
4
5
6
7
std::map<char, int> themap;

while (tekstas.get(ch))
{
	if (isalnum(ch))
		themap[ch]++;
}


You should either use tabs, or spaces. Using both is causing your formatting to be all messed up.
Last edited on
Thank you very much !
Topic archived. No new replies allowed.