hi
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
fstream file("a.txt",fstream::in|fstream:
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:
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:
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:
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:
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:
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:
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:
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:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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:
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:
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:
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:
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:
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:
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:
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:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>:
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>
]