input and output questions about file

J

James Kuyper

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.
 
J

James Kuyper

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(){".
 
D

Doug Miller

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.
 
R

Rui Maciel

Doug said:
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
 
R

Richard Bos

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
 
R

Richard Bos

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
 
S

Sjouke Burry

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.
 
C

CBFalconer

#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++.
 
J

jacob navia

hi

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

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream::eek:ut|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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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>::eek:perator
<<(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>::eek:perator
<<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(__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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator
<<(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
char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
char &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
char &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
*)(std::basic_istream<_Elem,_Traits> &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
*)(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(__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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(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>::eek:perator >>(void *&)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files (x86)\Microsoft Visual Studio
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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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::eek:perator
<<<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>::eek:perator
<<(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>::eek:perator
<<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(__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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator <<(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>::eek:perator
<<(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>
]
 
S

Spiros Bousbouras

//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?
 
S

Spiros Bousbouras

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.
 
J

jameskuyper

Spiros said:
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.
 
N

Nate Eldredge

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.
 
K

Keith Thompson

James said:
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.
 
J

James Kuyper

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top