Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric VC++ vs g++ query
    primarykey
    data
    text
    <p>I have trouble understanding the compilers. The following code does work in UNIX under g++, but under VC++ it would not even compile. Anyone can provide valid reasons why?</p> <pre><code>#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 (strlen(buffer.c_str()) &gt;15 ) { tmp_nw_msg = buffer.substr(1,12); crc_chksum = buffer.substr(13,2); cout &lt;&lt; " N/W msg : "&lt;&lt; tmp_nw_msg &lt;&lt; endl; cout &lt;&lt; " crc chksum : "&lt;&lt; crc_chksum &lt;&lt; endl; } else { cout &lt;&lt; "error" &lt;&lt; endl; } std::cin.get(); return 0; } </code></pre> <p>The following error is thrown by VC++, but in g++ it does work fine.</p> <blockquote> <p>Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\documents and settings\my documents\visual studio 2005\projects\dummy_substr\dummy_substr\substr.cpp 13<br> Error 2 error C2679: binary '&lt;&lt;' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\documents and settings\my documents\visual studio 2005\projects\dummy_substr\dummy_substr\substr.cpp 19<br> Error 3 error C2679: binary '&lt;&lt;' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\documents and settings\my documents\visual studio 2005\projects\dummy_substr\dummy_substr\substr.cpp 20<br> Error 4 fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\my documents\visual studio 2005\projects\dummy_substr\dummy_substr\substr.cpp(9)' was matched c:\documents and settings\my documents\visual studio 2005\projects\dummy_substr\dummy_substr\substr.cpp 29</p> </blockquote> <p>Output from g++ : </p> <blockquote> <p>Enter the string : BD2d1100mayor47E N/W msg : D2d1100mayor crc chksum : 47</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload