Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When i reading file i receiving some numerics and letters

When i trying to read from file text, occurs numerics and letters
This is my GreenLang.cpp:

#include <iostream>
#include <string>
#include <fstream>

class ScanErrors {
protected:
    char* element;
    char codeElement;
    std::string path;
    std::string source;

public:
    ScanErrors (std::string filePath) {

        std::ifstream fileRead;
        fileRead.open(filePath);
        while (!fileRead.eof()) {
            fileRead.get(codeElement);
            scan(codeElement);
        }
        fileRead.close();
    }
    
    void scan(char code) {
        std::cout << code << std::endl;
        std::cout << std::to_string(code);
    }
};

int main() {
    ScanErrors scanner("code.gl");

    return 0;
}

This is my code.gl:
Hello, World!

My output:
H
72e
101l
108l
108o
111,
44
32W
87o
111r
114l
108d
100!
33!
33
Why these weird numerics appears?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to print only the characters and not their ASCII values, you can remove the line std::cout << std::to_string(code); from your scan function:

void scan(char code) {
    std::cout << code << std::endl;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading