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?
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string tmp_nw_msg, crc_chksum, buffer;
cout << "Enter the string : ";
cin >> buffer;
if (strlen(buffer.c_str()) >15 ) {
tmp_nw_msg = buffer.substr(1,12);
crc_chksum = buffer.substr(13,2);
cout << " N/W msg : "<< tmp_nw_msg << endl;
cout << " crc chksum : "<< crc_chksum << endl;
}
else {
cout << "error" << endl;
}
std::cin.get();
return 0;
}
The following error is thrown by VC++, but in g++ it does work fine.
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 Error 2 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 19 Error 3 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 20 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
Output from g++ :
Enter the string : BD2d1100mayor47E N/W msg : D2d1100mayor crc chksum : 47