Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 510441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:06:50+00:00 2026-05-13T07:06:50+00:00

I have trouble understanding the compilers. The following code does work in UNIX under

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:06:50+00:00Added an answer on May 13, 2026 at 7:06 am

    You need to replace #include <string.h> by #include <string>

    C++ headers don’t have the .h extension to differentiate them from C headers that would have the same name.

    Also, you don’t need the #include <stdio.h> header for your program — and in case you need to call stdio functions from a C++ program you should #include <cstio> anyway.


    EDIT: “If that really was the problem, the error should be on the definition of the string variables” commented by PierreBdR

    In MSVC++, #include <iostream> creates a cascade of includes which at some point #include <stdexcept>. Then when you look at the stdexcept header file, you can see #include <xstring>. MSVC++ definition and implementation of std::string really is in this xstring header which explains why the compiler knows the type even-though you didn’t #include <string>.

    Then if you look at the content of the string header, you can see this is where binary operators compatible with std::string are defined which explains why the error only pops up on the line containing cin >> buffer; statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Conceptually, I would like to accomplish the following but have had trouble understand how
Conceptually, I would like to accomplish the following but have had trouble understand how
I have trouble with the following piece of code. When I go through with
I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations
I am developing a small windows app, but have some trouble deciding whether to
I have trouble understanding the gcc compiler provided by OSX 10.6 snow leopard, mainly
I have trouble understanding Cocoa Bindings. Can someone explain me what this is all
I have real trouble understanding mod_rewrite, and got some help in creating a RewriteRule
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble using Perl grep() with a string that may contain chars that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.