input and output questions about file #2

  • Follow


hi

#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

int main()
{
 fstream file("a.txt",fstream::in|fstream::out|fstream::app);
 string s1,s2;

  if(!file) cerr<<"error"<<endl; //why the program have
                                              //error when connecting
up "a.txt"

  s1="abcd 1234\n";
  file<<s1;   //why don't write in a.txt?
  file.flush();
  file.seekg(0);
  file>>s2;
  cout<<"s2="<<s2<<endl;//s2 is empty

  file.close();

getch();
return 0;}

the program can run without any error,but the result is:

error

s2=

the program don't create file "a.txt",How do i do?
0
Reply george972 (8) 5/25/2009 4:56:50 PM

On May 25, 2009 12:56, in comp.lang.c, george972@mailinator.com
(george972@mailinator.com) wrote:

> hi
> 
> #include<iostream>
> #include<conio.h>
> #include<fstream>
> 
> using namespace std;
> 
> int main()
> {
>  fstream file("a.txt",fstream::in|fstream::out|fstream::app);
[snip]
> the program don't create file "a.txt",How do i do?

You ask the kind folks in comp.lang.c++ to help you.

(You present a problem with a C++ program; why would you expect the folk in
comp.lang.C to be of assistance? C is not C++ and C++ is not C.)

HTH
-- 
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/   | GPG public key available by request
----------      Slackware - Because I know what I'm doing.          ------


0
Reply lpitcher2 (869) 5/25/2009 5:11:56 PM


george972@mailinator.com wrote:
> hi
> 
> #include<iostream>

<snip>

You are asking about C++ so you need to ask in comp.lang.c++, this group 
is for C which does not have fstream etc.
-- 
Flash Gordon
0
Reply smap (838) 5/25/2009 5:16:43 PM

george972@mailinator.com writes:

> #include<iostream>

You are using C++ so you should post in comp.lang.c++.

<snip>
-- 
Ben.
0
Reply ben.usenet (6515) 5/25/2009 5:21:26 PM

Hi

You guys need to chill the fuck out brothers. Replace fstream with
open/read/write if you want, its just the same.

Regards,


On May 25, 6:21=A0pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> george...@mailinator.com writes:
> > #include<iostream>
>
> You are using C++ so you should post in comp.lang.c++.
>
> <snip>
> --
> Ben.

0
Reply george972 (8) 5/25/2009 5:48:14 PM

In article <25751f7c-a79a-43c3-9ce6-4215ade83b51@p4g2000vba.googlegroups.com>, george972@mailinator.com wrote:
>Hi
>
>You guys need to chill the fuck out brothers. Replace fstream with
>open/read/write if you want, its just the same.

First, you come here asking questions about a different language than the one 
which is the subject of this group.

Then, you get shirty with the people who politely point out -- correctly -- 
that you're in the wrong group. 

Does that sound like a recipe for getting any further assistance here?

0
Reply spambait4 (1174) 5/25/2009 6:17:25 PM

In article <RgBSl.30415$Ws1.18113@nlpi064.nbdc.sbc.com>,
Doug Miller <spambait@milmac.com> wrote:
>In article
><25751f7c-a79a-43c3-9ce6-4215ade83b51@p4g2000vba.googlegroups.com>,
>george972@mailinator.com wrote:
>>Hi
>>
>>You guys need to chill the fuck out brothers. Replace fstream with
>>open/read/write if you want, its just the same.
>
>First, you come here asking questions about a different language than the one 
>which is the subject of this group.
>
>Then, you get shirty with the people who politely point out -- correctly -- 
>that you're in the wrong group. 
>
>Does that sound like a recipe for getting any further assistance here?

Dear OP: You've just been threatened with a denial of service if you
don't play by their rules.  This is a common tactic used frequently by
the people who control this newsgroup and want/need to maintain their
control.

Trust me, you don't want their help; they never give any usable help
anyway (*).  You can tell them, for me, to FO with their rules and their
control.

(*) It is an explicit part of the design of how they keep control.  They
never give any usable help - for example, they explicitly refuse to have
anything to do with anything that they think might be "homework".

0
Reply gazelle3 (1598) 5/25/2009 6:24:01 PM

On May 25, 2009 13:48, in comp.lang.c, george972@mailinator.com
(george972@mailinator.com) wrote:

> Hi
> 
> You guys need to chill the fuck out brothers. Replace fstream with
> open/read/write if you want, its just the same.

I'd much rather replace your fstream() with
     SELECT UT-S-SYSIN ASSIGN STREAM-IN.
   
  FD STREAM-IN RECORD IS 80, BLOCK IS 8000, LABEL RECORD IS STANDARD.
  01 STREAM-DATA             PIC X(80).


     OPEN INPUT STREAM-IN.
     READ STREAM-DATA.

but, then again, I would have coded something as much related to C as you
have. And both would be off topic here.

Yours would be on-topic in comp.lang.C++
Mine would be on-topic in comp.lang.COBOL


HTH, HAND
-- 
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/   | GPG public key available by request
----------      Slackware - Because I know what I'm doing.          ------


0
Reply lpitcher2 (869) 5/25/2009 6:45:55 PM

george972@mailinator.com wrote:
> Hi
> 
> You guys need to chill the fuck out brothers. Replace fstream with
> open/read/write if you want, its just the same.

open/read/write would be for comp.unix.programming. For comp.lang.c, 
its' fopen(), fread(), and fwrite().

No, they are not the same. The rules governing the <iostream> portion of 
the C++ standard library are connected to the rules governing the 
<stdio.h> portion of the C standard library; but the relationship is 
fairly complex, and many of the people who post to this newsgroup, oddly 
enough, are completely unaware of what that relationship is. The people 
who best understand that relationship best are mostly C++ programmers.

If you think that translating your C++ code into C is so trivial; try 
converting it yourself. If, after you've completed the translation, you 
still see the same problem, post it here and we'll be glad to help you 
with it.
0
Reply jameskuyper (5171) 5/25/2009 9:19:39 PM

In article <gveno1$p12$1@news.xmission.com>, gazelle@shell.xmission.com (Kenny McCormack) wrote:
>In article <RgBSl.30415$Ws1.18113@nlpi064.nbdc.sbc.com>,
>Doug Miller <spambait@milmac.com> wrote:
>>In article
>><25751f7c-a79a-43c3-9ce6-4215ade83b51@p4g2000vba.googlegroups.com>,
>>george972@mailinator.com wrote:
>>>Hi
>>>
>>>You guys need to chill the fuck out brothers. Replace fstream with
>>>open/read/write if you want, its just the same.
>>
>>First, you come here asking questions about a different language than the one 
>>which is the subject of this group.
>>
>>Then, you get shirty with the people who politely point out -- correctly -- 
>>that you're in the wrong group. 
>>
>>Does that sound like a recipe for getting any further assistance here?
>
>Dear OP: You've just been threatened with a denial of service if you
>don't play by their rules.  This is a common tactic used frequently by
>the people who control this newsgroup and want/need to maintain their
>control.

Oh, for crying out loud. "Denial of service" my foot. Were you born this 
dense, or did you train? When a question is posted to the wrong group, there's 
no reasonable expectation of any "service" beyond being pointed to the *right* 
group -- which is exactly what he got.

0
Reply spambait4 (1174) 5/25/2009 9:33:42 PM

spambait@milmac.com (Doug Miller) writes:
> In article <gveno1$p12$1@news.xmission.com>,
> gazelle@shell.xmission.com (Kenny McCormack) wrote:
[more of the same]
>
> Oh, for crying out loud.
[...]

Please don't feed the troll.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
0
Reply kst-u (21489) 5/25/2009 9:47:28 PM

george972 wrote:
> Ben Bacarisse wrote:
> > george...@mailinator.com writes:
> > > #include<iostream>
> >
> > You are using C++ so you should post in comp.lang.c++.
>
> You guys need to chill the fuck out brothers. Replace fstream with
> open/read/write if you want, its just the same.

And you need to consider how much you're paying us before you treat us
like that.
0
Reply blargg.ei3 (369) 5/25/2009 9:57:16 PM

In article <gveno1$p12$1@news.xmission.com>, gazelle@shell.xmission.com (Kenny McCormack) wrote:

>Dear OP: You've just been threatened with a denial of service if you
>don't play by their rules.  This is a common tactic used frequently by
>the people who control this newsgroup and want/need to maintain their
>control.
>
>Trust me, you don't want their help; they never give any usable help
>anyway (*).  You can tell them, for me, to FO with their rules and their
>control.
>
>(*) It is an explicit part of the design of how they keep control.  They
>never give any usable help - for example, they explicitly refuse to have
>anything to do with anything that they think might be "homework".
>

So what is *your* reason for not providing any help? Ass.
0
Reply spambait4 (1174) 5/25/2009 10:10:23 PM

In article <blargg.ei3-2505091657160001@192.168.1.4>,
blargg <blargg.ei3@gishpuppy.com> wrote:
>george972 wrote:
>> Ben Bacarisse wrote:
>> > george...@mailinator.com writes:
>> > > #include<iostream>
>> >
>> > You are using C++ so you should post in comp.lang.c++.
>>
>> You guys need to chill the fuck out brothers. Replace fstream with
>> open/read/write if you want, its just the same.
>
>And you need to consider how much you're paying us before you treat us
>like that.

I think that George has figured out that he's not gettin' squat from you
turds.  It doesn't take much reading in this newsgroup to figure that out.

0
Reply gazelle3 (1598) 5/25/2009 10:44:30 PM

In article <nHESl.17679$%54.4705@nlpi070.nbdc.sbc.com>,
Doug Miller <spambait@milmac.com> wrote:
>In article <gveno1$p12$1@news.xmission.com>, gazelle@shell.xmission.com
>(Kenny McCormack) wrote:
>
>>Dear OP: You've just been threatened with a denial of service if you
>>don't play by their rules.  This is a common tactic used frequently by
>>the people who control this newsgroup and want/need to maintain their
>>control.
>>
>>Trust me, you don't want their help; they never give any usable help
>>anyway (*).  You can tell them, for me, to FO with their rules and their
>>control.
>>
>>(*) It is an explicit part of the design of how they keep control.  They
>>never give any usable help - for example, they explicitly refuse to have
>>anything to do with anything that they think might be "homework".
>>
>
>So what is *your* reason for not providing any help? Ass.

I don't pretend to be anything other than what I am - a commentator on
the social norms of this newsgroup.

0
Reply gazelle3 (1598) 5/25/2009 10:45:25 PM

In article <gvf725$3mo$2@news.xmission.com>, gazelle@shell.xmission.com (Kenny McCormack) wrote:
>In article <nHESl.17679$%54.4705@nlpi070.nbdc.sbc.com>,
>Doug Miller <spambait@milmac.com> wrote:
>>In article <gveno1$p12$1@news.xmission.com>, gazelle@shell.xmission.com
>>(Kenny McCormack) wrote:
>>
>>>Dear OP: You've just been threatened with a denial of service if you
>>>don't play by their rules.  This is a common tactic used frequently by
>>>the people who control this newsgroup and want/need to maintain their
>>>control.
>>>
>>>Trust me, you don't want their help; they never give any usable help
>>>anyway (*).  You can tell them, for me, to FO with their rules and their
>>>control.
>>>
>>>(*) It is an explicit part of the design of how they keep control.  They
>>>never give any usable help - for example, they explicitly refuse to have
>>>anything to do with anything that they think might be "homework".
>>>
>>
>>So what is *your* reason for not providing any help? Ass.
>
>I don't pretend to be anything other than what I am - a commentator on
>the social norms of this newsgroup.
>
IOW -- a net-nanny.

<plonk>
0
Reply spambait4 (1174) 5/25/2009 11:11:55 PM

george972@mailinator.com wrote:
> Right you are brother, substitute malloc/free if you like, it's just
> the same...

george972@mailinator.com wrote:
> You guys need to chill the f--- out brothers. Replace fstream with
> open/read/write if you want, its just the same.

I wonder what's next to be just the same between C++ and C..

-- 
bart


0
Reply bartc (783) 5/26/2009 12:06:39 AM

george972@mailinator.com wrote:
> Hi
> 
> You guys need to chill the fuck out brothers. Replace fstream with
> open/read/write if you want, its just the same.

     Okay, I'm chilled, and I've done as you suggest.  The
compiler tells me

moron.c:1:19: iostream: No such file or directory (ENOENT)
moron.c:3:26: open/read/write: No such file or directory (ENOENT)
moron.c:5: error: parse error before "namespace"
moron.c:5: warning: type defaults to `int' in declaration of `std'
moron.c:5: error: ISO C forbids data definition with no type or storage 
class
moron.c: In function `main':
moron.c:9: error: `open' undeclared (first use in this function)
moron.c:9: error: (Each undeclared identifier is reported only once
moron.c:9: error: for each function it appears in.)
moron.c:9: error: `read' undeclared (first use in this function)
moron.c:9: error: `write' undeclared (first use in this function)
moron.c:9: error: parse error before "file"
moron.c:10: error: `string' undeclared (first use in this function)
moron.c:12: error: `file' undeclared (first use in this function)
moron.c:12: error: `cerr' undeclared (first use in this function)
moron.c:12: error: `endl' undeclared (first use in this function)
moron.c:12: error: parse error before '/' token
moron.c:17: error: `s1' undeclared (first use in this function)
moron.c:17: error: parse error before '/' token
moron.c:17:23: missing terminating ' character
moron.c:17:23: warning: character constant too long for its type
moron.c:20: error: `s2' undeclared (first use in this function)
moron.c:21: error: `cout' undeclared (first use in this function)
moron.c:21: error: parse error before '/' token
moron.c:25: warning: implicit declaration of function `getch'

Compilation exited abnormally with code 1 at Mon May 25 20:11:20

.... so what should I try next?

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
0
Reply esosman2 (2945) 5/26/2009 12:15:02 AM

On May 25, 12:48=A0pm, george...@mailinator.com wrote:
> Hi
>
> You guys need to chill the fuck out brothers. Replace fstream with
> open/read/write if you want, its just the same.
>
> Regards,
>
> On May 25, 6:21=A0pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
> > george...@mailinator.com writes:
> > > #include<iostream>
>
> > You are using C++ so you should post in comp.lang.c++.
>
> > <snip>
> > --
> > Ben.
>
>

Wow. Top-posted foul-mouthed overreaction to genuine
council concerning his own faux-pas. Didn't the same
thing happen the other day?

If it smells like one and gobbles little goats...

--
laser chicken
0
Reply mijoryx (954) 5/26/2009 12:35:26 AM

please don't top-post. Post your reply *after* what
you are replying to.

On 25 May, 18:48, george...@mailinator.com wrote:
> Hi
>
> You guys need to chill the <expletive> out brothers. Replace fstream with
> open/read/write if you want, its just the same.

none of fstream, open, read or write are defined by the C standard.
I'm not quite sure where to direct you to now.


> On May 25, 6:21=A0pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
>
>
> > george...@mailinator.com writes:
> > > #include<iostream>
>
> > You are using C++ so you should post in comp.lang.c++.

0
Reply nick_keighley_nospam (4574) 5/26/2009 7:35:57 AM

Ok, so why do you guys need to play the dumbass, brothers?

I write my code in C++ for power and flexibility, but in this instance
I'm interested in what's happening at the level of the underlying C
calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
answer the fucking question? Why do you think I'm pissing on your
roses just because I use C++, brothers?

Regards,


On May 26, 8:35=A0am, nick_keighley_nos...@hotmail.com wrote:
> please don't top-post. Post your reply *after* what
> you are replying to.
>
> On 25 May, 18:48, george...@mailinator.com wrote:
>
> > Hi
>
> > You guys need to chill the <expletive> out brothers. Replace fstream wi=
th
> > open/read/write if you want, its just the same.
>
> none of fstream, open, read or write are defined by the C standard.
> I'm not quite sure where to direct you to now.
>
> > On May 25, 6:21=A0pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
> > > george...@mailinator.com writes:
> > > > #include<iostream>
>
> > > You are using C++ so you should post in comp.lang.c++.
>
>

0
Reply george972 (8) 5/26/2009 9:05:19 AM

george972@mailinator.com wrote:
> Ok, so why do you guys need to play the dumbass, brothers?

We're not. Oddly enough, people who know a lot about C++ tend to be 
poorly represented in this newsgroup. The number of people here who can 
translate your C++ code into corresponding C code is probably small. The 
number who can be certain that the translated code has exactly the same 
required behavior as the original is much smaller. I think you radically 
underestimate how much your code depends upon C++. The largest 
consecutive string of tokens in your program that makes no use of C++ 
specific features is "; int main(){".

> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls.  ...

The C++ standard library incorporates much of the C standard library by 
reference, with modifications. It would be entirely possible to 
implement much of it terms of calls to the C standard library, and 
implementations that work in just that fashion have been historically 
quite important. However, it's entirely possible that the C++ <iostream> 
templates make direct use of the OS rather than going through the C 
<stdio.h> functions, or that both the C++ library and C libraries call 
common implementation-specific subroutines.

Most importantly, even if there are underlying C calls, the relationship 
between the C++ code and the C code is complicated, and you can't 
reasonably expect people on this newsgroup to be well informed about 
that relationship.

For example, the very first statement of main() constructs an fstream 
object, which is a typedef for basic_fstream<char, char_traits<char> >, 
a class derived from basic_iostream, which in turn inherits from both 
basic_istream and basic_ostream, both of which, in turn, inherit 
virtually from basic_ios. All of those base classes must be constructed, 
and figuring out the required behavior for the fstream constructor 
requires tracking down the required behavior of each of those 
constructors. That includes creation of a basic_filebuf, which is 
inherited from basic_streambuf, and which must ultimately be passed to 
basic_ios::init().

The C++ standard is far more specific about what precisely happens when 
you construct an fstream than the C standard is about what happens when 
you call fopen(). It has to be, because it is intended to be possible to 
define your own classes derived from basic_ios, basic_istream, or 
basic_streambuf, and to instantiate the standard templates with 
user-defined class types as template arguments.

Do you really think that a group devoted to C is the best place to ask 
for advice about how such a complicated system of C++ code is supposed 
to work?

 > ... Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question?  ...

This has nothing to do with rivalry, and everything to do with 
expertise. You're not likely to find the expertise you need here.

> ... Why do you think I'm pissing on your
> roses just because I use C++, brothers?
0
Reply jameskuyper (5171) 5/26/2009 11:03:23 AM

James Kuyper wrote:
....
> underestimate how much your code depends upon C++. The largest 
> consecutive string of tokens in your program that makes no use of C++ 
> specific features is "; int main(){".

Sorry, I'm having trouble with my computer system - for no obvious 
reason it seems to be shifting character encodings in the middle of a 
composing a message. That was supposed to read "; int main(){".
0
Reply jameskuyper (5171) 5/26/2009 11:08:00 AM

In article <05763151-37e6-460e-a462-08fbd4d56121@n4g2000vba.googlegroups.com>, george972@mailinator.com wrote:
>Ok, so why do you guys need to play the dumbass, brothers?
>
>I write my code in C++ for power and flexibility, but in this instance
>I'm interested in what's happening at the level of the underlying C
>calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
>answer the fucking question? Why do you think I'm pissing on your
>roses just because I use C++, brothers?

Some supposed "rivalry" has nothing to do with it. C and C++ are different 
languages. Similar, certainly, but different. You come to a C newsgroup asking 
questions about the behavior of a C++ program, and then get testy, angry, and 
vulgar when you're told, politely, that you'd be better off asking your 
questions in a C++ newsgroup.

Tell me again who's "playing the dumbass" here.
0
Reply spambait4 (1174) 5/26/2009 11:20:39 AM

Doug Miller wrote:

> Some supposed "rivalry" has nothing to do with it. C and C++ are different
> languages. Similar, certainly, but different. You come to a C newsgroup
> asking questions about the behavior of a C++ program, and then get testy,
> angry, and vulgar when you're told, politely, that you'd be better off
> asking your questions in a C++ newsgroup.
> 
> Tell me again who's "playing the dumbass" here.

The thread was started with a message that was naturally and rightfully going to receive redirect 
suggestions. It was started by someone hiding behind a mailinator address who, after the very first redirect 
suggestion, started spreading insults all around while making inflammatory statements.

So, to put it in other words, it's a troll. A poorly conceived one, too.

So please don't feed it.


Rui Maciel

0
Reply rui.maciel (1746) 5/26/2009 11:43:14 AM

James Kuyper wrote:
> James Kuyper wrote:
> ...
>> underestimate how much your code depends upon C++. The largest 
>> consecutive string of tokens in your program that makes no use of C++ 
>> specific features is "; int main(){".
> 
> Sorry, I'm having trouble with my computer system - for no obvious 
> reason it seems to be shifting character encodings in the middle of a 
> composing a message. That was supposed to read "; int main(){".

It showed up as

"; int main(){"

with no space after the semicolon, when I first read the original.

-- 
pete
0
Reply pfiland (6614) 5/26/2009 11:48:52 AM

george972@mailinator.com wrote:
> hi
> 
> #include<iostream>
> #include<conio.h>
> #include<fstream>
> 
> using namespace std;
> 
> int main()
> {
>  fstream file("a.txt",fstream::in|fstream::out|fstream::app);
>  string s1,s2;
> 
>   if(!file) cerr<<"error"<<endl; //why the program have
>                                               //error when connecting
> up "a.txt"
> 
>   s1="abcd 1234\n";
>   file<<s1;   //why don't write in a.txt?
>   file.flush();
>   file.seekg(0);
>   file>>s2;
>   cout<<"s2="<<s2<<endl;//s2 is empty
> 
>   file.close();
> 
> getch();
> return 0;}
> 
> the program can run without any error,but the result is:
> 
> error
> 
> s2=
> 
> the program don't create file "a.txt",How do i do?


/* BEGIN new.c  output */

fopen(a.txt, "w") != NULL

a.txt is closed.

fopen(a.txt, "r") != NULL

abcd 1234

a.txt is closed.

a.txt has been removed.

/* END new.c  output */




/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>

#define FILE_NAME       "a.txt"
#define STRING          "abcd 1234\n"
#define LENGTH          80
#define str(x)          # x
#define xstr(x)         str(x)

int main(void)
{
     int rc;
     char *fn = FILE_NAME;
     FILE *fp;
     const char *const s1 = STRING;
     char s2[LENGTH];

     puts("/* BEGIN new.c  output */\n");
     fp = fopen(fn, "w");
     if (fp == NULL) {
         printf("fopen(%s, \"w\") == NULL\n", fn);
         exit(EXIT_FAILURE);;
     } else {
         printf("fopen(%s, \"w\") != NULL\n", fn);
     }
     fputs(s1, fp);
     fclose(fp);
     printf("\n%s is closed.\n\n", fn);
     fp = fopen(fn, "r");
     if (fp == NULL) {
         printf("fopen(%s, \"r\") == NULL\n", fn);
         exit(EXIT_FAILURE);;
     } else {
         printf("fopen(%s, \"r\") != NULL\n\n", fn);
     }
     do {
         rc = fscanf(fp, "%" xstr(LENGTH) "[^\n]%*[^\n]", s2);
         if (!feof(fp)) {
             getc(fp);
         }
         if (rc == 0) {
             *s2 = '\0';
         }
         if (rc != EOF) {
             puts(s2);
         }
     } while (rc != EOF);
     fclose(fp);
     printf("\n%s is closed.\n", fn);
     remove(fn);
     printf("\n%s has been removed.\n", fn);
     puts("\n/* END new.c  output */");
	return 0;
}

/* END new.c */

-- 
pete
0
Reply pfiland (6614) 5/26/2009 11:51:38 AM

spambait@milmac.com (Doug Miller) wrote:

> In article <25751f7c-a79a-43c3-9ce6-4215ade83b51@p4g2000vba.googlegroups.com>, george972@mailinator.com wrote:

> >You guys need to chill the fuck out brothers. Replace fstream with
> >open/read/write if you want, its just the same.
> 
> First, you come here asking questions about a different language than the one 
> which is the subject of this group.
> 
> Then, you get shirty with the people who politely point out -- correctly -- 
> that you're in the wrong group. 
> 
> Does that sound like a recipe for getting any further assistance here?

Well, it's just about a guaranteed method for getting on Han's soft
side, so I'd think that it does.

Richard
0
Reply raltbos (821) 5/26/2009 12:06:19 PM

gazelle@shell.xmission.com (Kenny McCormack) wrote:

> Dear OP: You've just been threatened with a denial of service if you
> don't play by their rules.  This is a common tactic used frequently by
> the people who control this newsgroup and want/need to maintain their
> control.

Don't be an idiot, Kenny. _Nobody_ controls this newsgroup, not even you
and your arse buddies.

Richard
0
Reply raltbos (821) 5/26/2009 12:06:20 PM

pete wrote:

>     char s2[LENGTH];

That should be

     char s2[LENGTH + 1];

instead.

>         rc = fscanf(fp, "%" xstr(LENGTH) "[^\n]%*[^\n]", s2);


-- 
pete
0
Reply pfiland (6614) 5/26/2009 12:36:53 PM

george972@mailinator.com wrote:
> Ok, so why do you guys need to play the dumbass, brothers?
> 
> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question? Why do you think I'm pissing on your
> roses just because I use C++, brothers?
> 
Trolling is the only and sufficient reason.
0
Reply burrynulnulfour (424) 5/26/2009 2:59:40 PM

george972@mailinator.com wrote:
> Ok, so why do you guys need to play the dumbass, brothers?
> 
> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls.

First there may be no underlying C calls because you are in C++.  If there is
the C library does pretty much what you would expect it to do.  It may make sure
the arguments passed make sense throwing errors if they don't, re-arranges them
if need be and calls the O/S.  Now when you get to the O/S you are out of C and
will need to ask elsewhere.  You could get a copy of The Standard C Library by
P.J Plauger for one possible implementation.

> Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question? Why do you think I'm pissing on your
> roses just because I use C++, brothers?

Because we damn well know we don't have the foggiest idea brother what the C++
compiler does.  For all we know it may intercept calls to the C library and
replace them with C++ calls.

If you want to ask about C, write in C and post here.  But don't ask about UNIX,
POSIX, Linux, Windows, C++, C#, COBOL or whatever here because that isn't C.
0
Reply gldncagrls (469) 5/26/2009 5:18:27 PM

george972@mailinator.com wrote:
> 
> #include<iostream>
> #include<conio.h>
> #include<fstream>
> 
> using namespace std;

This program is in C++.  This newsgroup is comp.lang.c.  This
message is off-topic.  Try comp.lang.c++.

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>
            Try the download section.

0
Reply cbfalconer (19183) 5/26/2009 7:41:59 PM

george972@mailinator.com wrote:
> hi
> 
> #include<iostream>
> #include<conio.h>
> #include<fstream>
> 
> using namespace std;
> 
> int main()
> {
>  fstream file("a.txt",fstream::in|fstream::out|fstream::app);
>  string s1,s2;
> 
>   if(!file) cerr<<"error"<<endl; //why the program have
>                                               //error when connecting
> up "a.txt"
> 
>   s1="abcd 1234\n";
>   file<<s1;   //why don't write in a.txt?
>   file.flush();
>   file.seekg(0);
>   file>>s2;
>   cout<<"s2="<<s2<<endl;//s2 is empty
> 
>   file.close();
> 
> getch();
> return 0;}
> 
> the program can run without any error,but the result is:
> 
> error
> 
> s2=
> 
> the program don't create file "a.txt",How do i do?

I got this output from the compiler.
Ahhh I am SO glad I do not do C++

The error messages are completely incomprehensible... well at least for me.


gg.cpp
gg.cpp(16) : error C2679: binary '<<' : no operator found which takes a 
right-hand operand of type 'std::string' (or there is no acceptable 
conversion)
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(656): could be 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> 
&,const char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(703): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(741): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(788): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(912): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
signed char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(919): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(926): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
unsigned char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(933): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned 
char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(174): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_ostream<_Elem,_Traits> &(__cdecl 
*)(std::basic_ostream<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(180): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_ios<_Elem,_Traits> &(__cdecl 
*)(std::basic_ios<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(187): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl 
*)(std::ios_base &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(194): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(214): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(short)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(247): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(267): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(int)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(292): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(312): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(long)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(332): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(353): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(373): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(394): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(float)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(414): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(double)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(434): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(454): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(474): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_streambuf<_Elem,_Traits> *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         while trying to match the argument list '(std::fstream, 
std::string)'
gg.cpp(19) : error C2679: binary '>>' : no operator found which takes a 
right-hand operand of type 'std::string' (or there is no acceptable 
conversion)
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(995): could be 'std::basic_istream<_Elem,_Traits> 
&std::operator 
 >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed 
char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(1002): or 'std::basic_istream<_Elem,_Traits> 
&std::operator 
 >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed 
char &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(1009): or 'std::basic_istream<_Elem,_Traits> 
&std::operator 
 >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned 
char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(1016): or 'std::basic_istream<_Elem,_Traits> 
&std::operator 
 >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned 
char &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(155): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator 
 >>(std::basic_istream<_Elem,_Traits> &(__cdecl 
*)(std::basic_istream<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(161): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator 
 >>(std::basic_ios<_Elem,_Traits> &(__cdecl 
*)(std::basic_ios<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(168): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl 
*)(std::ios_base &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(175): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(194): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(short &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(228): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(247): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(int &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(273): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(291): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(long &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(309): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(unsigned long &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(329): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(348): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(367): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(float &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(386): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(double &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(404): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(422): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\istream(441): or 'std::basic_istream<_Elem,_Traits> 
&std::basic_istream<_Elem,_Traits>::operator 
 >>(std::basic_streambuf<_Elem,_Traits> *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         while trying to match the argument list '(std::fstream, 
std::string)'
gg.cpp(20) : error C2679: binary '<<' : no operator found which takes a 
right-hand operand of type 'std::string' (or there is no acceptable 
conversion)
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(656): could be 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> 
&,const char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(703): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(741): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(788): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(912): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
signed char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(919): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(926): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const 
unsigned char *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(933): or 'std::basic_ostream<_Elem,_Traits> 
&std::operator 
<<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned 
char)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(174): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_ostream<_Elem,_Traits> &(__cdecl 
*)(std::basic_ostream<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(180): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_ios<_Elem,_Traits> &(__cdecl 
*)(std::basic_ios<_Elem,_Traits> &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(187): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl 
*)(std::ios_base &))'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(194): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(214): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(short)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(247): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(267): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(int)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(292): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(312): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(long)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(332): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(353): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(373): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(394): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(float)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(414): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(double)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(434): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(454): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         C:\Program Files (x86)\Microsoft Visual Studio 
8\VC\INCLUDE\ostream(474): or 'std::basic_ostream<_Elem,_Traits> 
&std::basic_ostream<_Elem,_Traits>::operator 
<<(std::basic_streambuf<_Elem,_Traits> *)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]
         while trying to match the argument list 
'(std::basic_ostream<_Elem,_Traits>, std::string)'
         with
         [
             _Elem=char,
             _Traits=std::char_traits<char>
         ]


-- 
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
0
Reply jacob24 (973) 5/26/2009 8:09:57 PM

On 25 May, 17:56, george...@mailinator.com wrote:

>                                               //error when connecting

Note that C89 does not support // style comments.

>   file<<s1;   //why don't write in a.txt?

Here you shift file which must have type integer s1
places and discard the result so it's no wonder you
don't see any effects. It's even possible that an
optimising compiler would not produce any code
for this unless file or s1 had been declared as
volatile.

>   file>>s2;

Here once again you discard the result of the
calculation.

> return 0;}
>
> the program can run without any error,but the result is:
>
> error
>
> s2=
>
> the program don't create file "a.txt",How do i do?

How *do* you do?

--
See you later mailinator.
0
Reply spibou (1037) 5/26/2009 8:12:34 PM

On 26 May, 20:41, CBFalconer <cbfalco...@yahoo.com> wrote:

> Try comp.lang.c++.

I don't see how a group specialising in C's increment
operator would help the OP since the increment
operator appears nowhere in his code.

--
Who's your mama?
0
Reply spibou (1037) 5/26/2009 9:03:55 PM

Spiros Bousbouras wrote:
> On 25 May, 17:56, george...@mailinator.com wrote:
>
> >                                               //error when connecting
>
> Note that C89 does not support // style comments.

But C99 does; that's practically the only thing about his code that is
on-topic for this forum.
0
Reply jameskuyper (5171) 5/26/2009 10:22:57 PM

george972@mailinator.com writes:

> Ok, so why do you guys need to play the dumbass, brothers?
>
> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question? Why do you think I'm pissing on your
> roses just because I use C++, brothers?

Did you honestly expect something different, from your experience of
this group?

But I'll answer your question to the best of my ability, without
feigning ignorance about subjects that may or may not be on-topic here.

I don't know.

Code similar to yours worked when I ran it.  It looks to me like your
attempt to open the file fails.  Your code doesn't contain any mechanism
for inquiring as to why the failure occurred.  It could be an error
reported by the operating system; perhaps you don't have permission to
create or open the file, or the disk is full, or you have too many files
open already.  The causes will likely be platform-dependent and nothing
to do with either the C or C++ languages themselves, and should probably
be probed further in a group relevant to your particular OS.

Your question is approximately as vague as asking "Why doesn't my car
start?" in an automotive forum.  There are many possible causes,
some of which will depend on the type of car you have.  Nobody can
answer the question without knowing more about the circumstances of the
failure, the solutions you have tried, the tests you have done.

My only idea would be to call perror() after the file fails to open.  On
many systems this will produce a useful error message which would likely
help.  I don't know whether yours is among them, because you didn't say
what it is.
0
Reply nate14 (514) 5/27/2009 4:35:01 AM

James Kuyper wrote:
> george972@mailinator.com wrote:
> > Ok, so why do you guys need to play the dumbass, brothers?
> 
> We're not. Oddly enough, people who know a lot about C++ tend to be 
> poorly represented in this newsgroup. The number of people here who can 
> translate your C++ code into corresponding C code is probably small. The 
> number who can be certain that the translated code has exactly the same 
> required behavior as the original is much smaller. I think you radically 
> underestimate how much your code depends upon C++. The largest 
> consecutive string of tokens in your program that makes no use of C++ 
> specific features is "int main(){".
[...]

Actually, it does, since int main() in C++ is equivalent to int main( void
), while in C it is equivalent to int main( ... ).
0
Reply blargg.ei3 (369) 5/27/2009 6:59:31 PM

blargg.ei3@gishpuppy.com (blargg) writes:
> James Kuyper wrote:
>> george972@mailinator.com wrote:
>> > Ok, so why do you guys need to play the dumbass, brothers?
>> 
>> We're not. Oddly enough, people who know a lot about C++ tend to be 
>> poorly represented in this newsgroup. The number of people here who can 
>> translate your C++ code into corresponding C code is probably small. The 
>> number who can be certain that the translated code has exactly the same 
>> required behavior as the original is much smaller. I think you radically 
>> underestimate how much your code depends upon C++. The largest 
>> consecutive string of tokens in your program that makes no use of C++ 
>> specific features is "int main(){".
> [...]
>
> Actually, it does, since int main() in C++ is equivalent to
> int main( void ), while in C it is equivalent to int main( ... ).

Not quite.  In C, a function declaration with empty parentheses
specifies that the function takes a fixed but unspecified number
and type(s) of arguments.  The function definition specifies the
arguments that it actually expects, but this is not enforced for
callers; it's up to the caller to get the arguments right, with
no help from the compiler.  (This is all that was available in
pre-ANSI C.)

The ellipsis (...) indicates that the function is variadic,
which means that the function itself needs to use <stdarg.h>
(or something equivalent to it) to obtain the argument values.
And there be must at least one preceding explicit parameter, so
int main(...), or even int foo(...), is illegal.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
0
Reply kst-u (21489) 5/27/2009 7:17:16 PM

george972@mailinator.com wrote:
> Ok, so why do you guys need to play the dumbass, brothers?
> 
> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question? Why do you think I'm pissing on your
> roses just because I use C++, brothers?

Your fstream constructor is conceptually similar to the following code, 
which works in C++ just as in C:

	FILE *file = fopen("a.txt", "a+");

However, the fstream interface doesn't currently support that 
combination of file opening modes, though it will be supported in the 
next version of the C++ standard. It could be quite a while before you 
can safely assume that the next version of the C++ standard library is 
fully implemented; even the current one (2003) is less than fully 
implemented on many platforms.

See the thread I started on comp.lang.c++.moderated for more details. 
It's titled "Opening file fore read, write, and append.", due to a typo.

You've just provided an excellent example of why it's a good idea to 
redirect questions that aren't actually about C, to a more appropriate 
newsgroup.
0
Reply jameskuyper (5171) 5/29/2009 10:48:37 AM

40 Replies
45 Views

(page loaded in 6.159 seconds)

Similiar Articles:


















7/28/2012 12:00:18 PM


Reply: