c++ - Generic VC++ vs g++ query -
I have trouble understanding compiler. The following code works under G ++ in Unix, but VC + Under this it will not even compile. Why can any reason provide any reason?
#include & lt; Stdio.h & gt; # Include & lt; Iostream & gt; #include & lt; String.h & gt; using namespace std; Int main () {string tmp_nw_msg, crc_chksum, buffer; Cout & lt; & Lt; "Enter the string:"; Cin & gt; & Gt; Buffer; If (strollon (buffer c_st ())> 15) {tmp_nw_msg = buffer sbbit (1,12); Crc_chksum = buffer concert (13,2); Cout & lt; & Lt; "N / W msg:" & lt; & Lt; Tmp_nw_msg & lt; & Lt; Endl; Cout & lt; & Lt; "CRC Chaksam:" & lt; & Lt; CRC_Chixam & lt; & Lt; Endl; } And {cout & lt; & Lt; "Error" & lt; & Lt; Endl; } Std :: cin.get (); Return 0; }
The following error has been thrown by VC ++, but this work is fine in G ++. Error 1 error C2679: binary '>>': No operator found that 'std :: string' (or no acceptable conversion) type 'std :: string' ' The right hand of C: \ documents and settings \ my documents \ visual studio 2005 \ projects \ dummy_substr \ dummy_substr \ substr.cpp 13
Error 4 Fatal error C1075: 'c: \ documents and settings \ my documents \ visual Studio 2005 \ projects \ dummy_substr \ dummy_substr \ substr.cpp (9)' on the left side brace 'C: \ documents and Settings \ my documents \ visual studio 2005 \ projects \ dummy_substr \ dummy_substr \ substr.cpp 29
Output from G ++:
Enter the string: BD2d1100mayor47E N / W msg: D2d1100mayor CRC chksum: 47
you #include & lt; String. H & gt; To change
#include & lt; String & gt;
C ++ headers do not have . H
extension to differentiate them from the C header that w can have names like this.
In addition to this, you must include #include & lt; Stdio.h & gt; Header is not required - and if you should work with the StaDio C ++ program, you should
#include & lt; Cstio & gt;
anyway.
Edit: "If this was really a problem, then there should be error definition of string variable" Commented by Peer BDR
In MSVC ++, #include & lt; Iostream & gt;
creates a waterfall in which at some point include #
stdexcept
header file, you can go to #include & lt; Xstring & gt;
can see. MSWC ++ definition and std :: string
are actually in this xstring
header that tells why the compiler knows the type-although you have the #include & Lt is not done; String & gt;
.
Then if you see the contents of the string
header, you can see that where binary operators are compatible std :: string
Is defined which indicates that the error is only for cin & gt; & Gt; Buffer;
statement.
Comments
Post a Comment