From: JoeC on
I cut and pasted a simple text file from one program to another. But
when I use the code in a different project it doesn't work. The
program just quits or something when it comes to the code. I am not
getting a crash or an error message and the code is the same as I had
used before:

#include<iostream>
#include<fstream>

using namespace std;

ofstream f("data.txt", ios::out); <-the program just exits here.

b1->save(f);
f.close();

void bitmap::save(std::ofstream& f){
for(int lp = 0; lp != bitData.size(); lp ++){
f<<bitData[lp]<<std::endl;
}
}



From: Richard Heathfield on
JoeC wrote:
> I cut and pasted a simple text file from one program to another. But
> when I use the code in a different project it doesn't work. The
> program just quits or something when it comes to the code.

To answer the question in your Subject line, yes, it's possible that
compilers have bugs BUT the chances of your revealing a bug in the
compiler are very low. In almost 30 years of programming, I've only
twice come across genuine bugs in C or C++ compilers "in the field" (as
opposed to corner cases found only on Usenet!). One of them was
amazingly obscure and it was sheer bad luck that I stumbled across it.
The other was a really stupid thing in VS6 which they fixed in the next
release. It is highly unlikely that you have found a compiler bug. Rule
1: don't blame the compiler, EVER. Rule 2 (for experts only): don't
blame the compiler, YET.

> I am not
> getting a crash or an error message and the code is the same as I had
> used before:
>
> #include<iostream>
> #include<fstream>
>
> using namespace std;
>
> ofstream f("data.txt", ios::out); <-the program just exits here.
>
> b1->save(f);

Since b1 is not defined, this code won't compile. I suggest you post the
real code.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: osmium on
"JoeC" wrote:

>I cut and pasted a simple text file from one program to another. But
> when I use the code in a different project it doesn't work. The
> program just quits or something when it comes to the code. I am not
> getting a crash or an error message and the code is the same as I had
> used before:
>
> #include<iostream>
> #include<fstream>
>
> using namespace std;
>
> ofstream f("data.txt", ios::out); <-the program just exits here.
>
> b1->save(f);
> f.close();
>
> void bitmap::save(std::ofstream& f){
> for(int lp = 0; lp != bitData.size(); lp ++){
> f<<bitData[lp]<<std::endl;
> }
> }

That's not a program, a C++ program has a function called "main" or
something similar to that. You have saved perhaps a minute or two and
wasted several hours, post the code.