Error with MessageBox on console.

I've been getting this problem with my program.
Every time I run it, it continually pops up blank messages.
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
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
//C:\\Documents and Settings\\All Users\\Documents\\crc\\


ifstream file_exists(const char * filename)
{
ifstream file(filename);
return file;
}
void del(){
remove("C:\\Documents and Settings\\All Users\\Documents\\crc\\con.txt");
remove("C:\\Documents and Settings\\All Users\\Documents\\crc\\mes.txt");
remove("C:\\Documents and Settings\\All Users\\Documents\\crc\\title.txt");
}

int main(){
	while(1){
	if (file_exists("C:\\Documents and Settings\\All Users\\Documents\\crc\\con.txt"))
	{
	ifstream title,mes;
	title.open("C:\\Documents and Settings\\All Users\\Documents\\crc\\title.txt");
	mes.open("C:\\Documents and Settings\\All Users\\Documents\\crc\\mes.txt");
	string ti,me;
	getline(title,ti); getline(mes,me);
	del();
	mes.close();
	title.close();
	MessageBoxA(NULL,me.c_str(),ti.c_str(),MB_OK);
	} // End of block
	else continue;
	
	
	} // End of while loop

} // End of main() 


If you will notice, its only supposed to display a message when "(file_exists("C:\\Documents and Settings\\All Users\\Documents\\crc\\con.txt"))" but instead, it pops up a message constantly.


Any help to this problem?
I was surprised it compiled in the first place - as streams aren't supposed to be copyable - so the
file_exists function shouldn't work.
If my function is faulty, it would explain why that is. Anyway do you have a suggestion for an alternative to file_exists?
The file_exists() function should return bool. That'll fix it.

The message pops up constantly because you never exit your loop.

Hope this helps.
Topic archived. No new replies allowed.