public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* A simple question of fstream
@ 2003-01-30 10:15 Ajay Bansal
  2003-01-30 10:23 ` Michal Liptak
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ajay Bansal @ 2003-01-30 10:15 UTC (permalink / raw)
  To: gcc-help

Hi All

I want from the following program to create a new file & write into it.
But it is not doing so. I am compiling with gcc 3.2.1

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <errno.h>
using namespace std;

int main()
{
fstream iostrm;

iostrm.open("new1.txt",ios::out | ios::in);

cout<<errno;
iostrm.write("gagan",5);

iostrm.close();

return 1;

}

What is wrong over here. If I compile the program using gcc 2.95, I get
a new file. 

-Ajay


PS: about my prior mails on compatibility issues with 2.95 & 3.2.1... I
am changing my code to meet with the standards.. 
:( :( 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A simple question of fstream
  2003-01-30 10:15 A simple question of fstream Ajay Bansal
@ 2003-01-30 10:23 ` Michal Liptak
  2003-01-30 12:53 ` John Love-Jensen
  2003-01-30 13:03 ` John Love-Jensen
  2 siblings, 0 replies; 6+ messages in thread
From: Michal Liptak @ 2003-01-30 10:23 UTC (permalink / raw)
  To: gcc-help

try this..

int main(void) {
ofstream of;
of.open("name");
if (of.fail()) return -1;
of<<"text";
of.close();
return 0;
}

m.

On Thu, 30 Jan 2003 14:01:12 +0530
"Ajay Bansal" <Ajay_Bansal@infosys.com> wrote:

>Hi All
>
>I want from the following program to create a new file & write into it.
>But it is not doing so. I am compiling with gcc 3.2.1
>
>#include <fstream>
>#include <iostream>
>#include <stdlib.h>
>#include <errno.h>
>using namespace std;
>
>int main()
>{
>fstream iostrm;
>
>iostrm.open("new1.txt",ios::out | ios::in);
>
>cout<<errno;
>iostrm.write("gagan",5);
>
>iostrm.close();
>
>return 1;
>
>}
>
>What is wrong over here. If I compile the program using gcc 2.95, I get
>a new file. 
>
>-Ajay
>
>
>PS: about my prior mails on compatibility issues with 2.95 & 3.2.1... I
>am changing my code to meet with the standards.. 
>:( :( 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A simple question of fstream
  2003-01-30 10:15 A simple question of fstream Ajay Bansal
  2003-01-30 10:23 ` Michal Liptak
@ 2003-01-30 12:53 ` John Love-Jensen
  2003-01-30 13:03 ` John Love-Jensen
  2 siblings, 0 replies; 6+ messages in thread
From: John Love-Jensen @ 2003-01-30 12:53 UTC (permalink / raw)
  To: Ajay Bansal, gcc-help

Hi Ajay,

I modified your example (see below), and it works for me (GCC 3.1 on OS X).

Sincerely,
--Eljay

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cerrno>
using namespace std;

int main()
{
    fstream iostrm;

    iostrm.open("new1.txt", ios_base::out | ios_base::in);

    cout << errno;
    iostrm.write("gagan", 5);

    iostrm.close();

    return 1;
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A simple question of fstream
  2003-01-30 10:15 A simple question of fstream Ajay Bansal
  2003-01-30 10:23 ` Michal Liptak
  2003-01-30 12:53 ` John Love-Jensen
@ 2003-01-30 13:03 ` John Love-Jensen
  2 siblings, 0 replies; 6+ messages in thread
From: John Love-Jensen @ 2003-01-30 13:03 UTC (permalink / raw)
  To: Ajay Bansal, gcc-help

Correction:

iostrm.open("new1.txt", ios_base::out | ios_base::in | ios_base::trunc);

--Eljay

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: A simple question of fstream
@ 2003-01-30 13:00 Ajay Bansal
  0 siblings, 0 replies; 6+ messages in thread
From: Ajay Bansal @ 2003-01-30 13:00 UTC (permalink / raw)
  To: John Love-Jensen, gcc-help

Still doesn't work with gcc 3.2.1, RH73

-----Original Message-----
From: John Love-Jensen [mailto:eljay@adobe.com] 
Sent: Thursday, January 30, 2003 6:19 PM
To: Ajay Bansal; gcc-help@gcc.gnu.org
Subject: Re: A simple question of fstream


Hi Ajay,

I modified your example (see below), and it works for me (GCC 3.1 on OS
X).

Sincerely,
--Eljay

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cerrno>
using namespace std;

int main()
{
    fstream iostrm;

    iostrm.open("new1.txt", ios_base::out | ios_base::in);

    cout << errno;
    iostrm.write("gagan", 5);

    iostrm.close();

    return 1;
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: A simple question of fstream
@ 2003-01-30 10:31 Ajay Bansal
  0 siblings, 0 replies; 6+ messages in thread
From: Ajay Bansal @ 2003-01-30 10:31 UTC (permalink / raw)
  To: Michal Liptak, gcc-help

I also figured one sol...

If I use 
iostrm.open("new1.txt",ios::out | ios::in | ios::trunc);

File is created. I just want to know the logic behind this


-----Original Message-----
From: Michal Liptak [mailto:liptak@isdd.sk] 
Sent: Thursday, January 30, 2003 3:57 PM
To: gcc-help@gcc.gnu.org
Subject: Re: A simple question of fstream


try this..

int main(void) {
ofstream of;
of.open("name");
if (of.fail()) return -1;
of<<"text";
of.close();
return 0;
}

m.

On Thu, 30 Jan 2003 14:01:12 +0530
"Ajay Bansal" <Ajay_Bansal@infosys.com> wrote:

>Hi All
>
>I want from the following program to create a new file & write into it.

>But it is not doing so. I am compiling with gcc 3.2.1
>
>#include <fstream>
>#include <iostream>
>#include <stdlib.h>
>#include <errno.h>
>using namespace std;
>
>int main()
>{
>fstream iostrm;
>
>iostrm.open("new1.txt",ios::out | ios::in);
>
>cout<<errno;
>iostrm.write("gagan",5);
>
>iostrm.close();
>
>return 1;
>
>}
>
>What is wrong over here. If I compile the program using gcc 2.95, I get

>a new file.
>
>-Ajay
>
>
>PS: about my prior mails on compatibility issues with 2.95 & 3.2.1... I

>am changing my code to meet with the standards.. :( :(

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-30 13:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-30 10:15 A simple question of fstream Ajay Bansal
2003-01-30 10:23 ` Michal Liptak
2003-01-30 12:53 ` John Love-Jensen
2003-01-30 13:03 ` John Love-Jensen
2003-01-30 10:31 Ajay Bansal
2003-01-30 13:00 Ajay Bansal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).