Input character by character?

How do I read a text file character by character?

I have a text file that includes:
abcdefghi


I want to make a program that reads that line, character by character.
I want this because I want to use a while loop that goes through the text character by character, and if it reads a "d", it prints everything before the "d" and stops right there.
It's my quick first attempt, unfortunately it's not working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	char d;
	ifstream readFile;
	readFile.open ("read.txt");  // Opens read.txt file

	while (readFile.good() && (char) readFile.get())
	{
		if(readFile.get() == "d")
		{
			break;
		}
		cout << readFile << endl;
	}
	system("pause");
	return 0;
}


The errors:
Error 2 error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]' 14
Error 1 error C2446: '==' : no conversion from 'const char *' to 'int' 14


Last edited on
Nevermind, I got it!
Topic archived. No new replies allowed.