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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I wasn't able to replicate your bug: var message =… May 13, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer Because WPF does not automatically reload from the binding source… May 13, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer you can see all of the request's form parameters like… May 13, 2026 at 10:37 pm

Related Questions

I have trouble understanding the gcc compiler provided by OSX 10.6 snow leopard, mainly
I'm having a little bit of trouble understanding what the problem is here. I
Now I have read and on this but i am just stuck. Any help
I’m having some trouble with understanding how IIS is handling static variables on its
This I think is related to my use of the nlog C++ API (and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.