I made a program in Visual Studio that reads an End-Of-File signal. When you run in the debug mode, sending the signal closes the program. Running without debugging with ctrl + F5 means you can send the signal. However, when I compile in release mode and run the exe it opens it in debug mode (or the same as the command line when you run as debugging) and the program closes when you send the EOF. How do I compile so you run it without debugging?

post a small example program that has the problem you describe because I don't quite understand what you are talking about.

I am using "accelerated C++", the code in chapter 3:

#include <iomanip>
#include <ios>
#include <iostream>
#include <string>

using std::cin;		using std::setprecision;
using std::cout;	using std::string;
using std::endl;	using std::streamsize;

int main()
{
	// ask for and read the students name
	cout << "Please enter your first name: ";
	string name;
	cin >> name;
	cout << "Hello, " << name << "!" << endl;

	// ask for and read the midterm grades
	cout << "Please enter your midterm and final exam grades: ";
	double midterm, final;
	cin >> midterm >> final;

	// ask for homework grades
	cout << "Enter all your homework grades, "
		"followed by end-of-file: ";

	// the number and sum of grades so far
	int count = 0;
	double sum = 0;
	// a variable in which to read
	double x;

	// invariant:
	//	we have read count grades so far, and
	//	sum is the sum of the first count grades
	while (cin >> x) {
		++count;
		sum += x;
	}

	// write the result
	streamsize prec = cout.precision();
	cout << "Your final grade is " << setprecision(3)
		<< 0.2 * midterm + 0.4 * final + 0.4 * sum / count
		<< setprecision(prec) << endl;

	cin.sync();
	cin.get();

	return 0;
}

Ctrl+F5 does not produce the eof signal the program is looking for. EOF is produced with Ctrl+Z key combination.

>>when I compile in release mode and run the exe it opens it in debug mode (or the same as the command line when you run as debugging)

Its supposed to do that because its a console program. That's a console window you see, not a debug window.

Yeah, I meant press ctrl+F5 in VS to run without debugging. Then I press ctrl+Z and it works, but when I run with debugging or the release executable, it just closes the console window.

And how, prey tell me, do you expect to enter your name and grades without a console window? What did you expect to see? Below is what I see when I run the program

A console window. But when I enter all of my homework grades and enter the EOF in debug and release the window closes, without writing the result.

I used VC++ 2008 Express and it worked for me (see bitmap in my previous post).

Now I understand, the problem is when you press F5 to start debugging. The Ctrl+Z sets some flags in cin that have to be cleared in order to get cin.get() or cin.ignore() to work properly.

cin.clear();
    cin.sync();
    cin.ignore();

Thanks, it works fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.