I'm attempting to read a text file character by character. I'm using a string to read the file. My code for reading the file is below:
int main()
{
std::ifstream data;
data.open("C:\\Users\\Christian Dean\\Documents\\CodeLiteWorkspace\\CplusplusPractice\\src\\test_file.qz");
std::string data_str;
int counter = 0;
data >> data_str;
for(int i = 0; i < data_str.length(); i++)
{
std::string tokenizer = data_str[i];
if (tokenizer == "output")
{
counter++;
}
}
std::cout << counter << std::endl;
data.close();
return 0;
}
as you can see, in my for loop I'm setting the string tokenizer
equal to the zeroth index of the string data_str
. However when compiling, it show the error
`main.cpp:27:37: error: invalid conversion from 'char' to ''const char*' [-fpermissive].
I really don't know how else I can read the file character by character. I tried setting tokenizer
as type char
. But when I run the program it says the counter
variable equals 0
. So obviously making the tokenizer
variable a type char
did not work.
The content of the text file is below if it is needed:
output: "Hello World