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 9192733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:59:48+00:00 2026-06-17T20:59:48+00:00

Possible Duplicate: Why isn’t cin >> string working with Visual C++ 2010? The first

  • 0

Possible Duplicate:
Why isn’t cin >> string working with Visual C++ 2010?

The first program I wrote refuses to compile in Visual C++, and it looks like it’s complaining that the ‘>>’ operator isn’t defined for istream.

After looking it over carefully, it seemed to be correct, so I checked with g++ and it compiles fine (and has no warnings with -Wall).

So why does it work with g++ but not Visual C++?

Here is the program:

#include <iostream>
#include <list>

int main() {
    std::list<std::string> list;
    std::string str = "";
    std::cin >> str;
    while (str.compare("q") != 0) {
        list.push_back(str);
        std::cin >> str;
    }

    std::cout << "You entered: \n";

    for (std::list<std::string>::iterator i = list.begin(); i != list.end(); i++) {
        std::cout << *i << std::endl;
    }
    return 0;
}

I had thought C++ code written for Visual C++ and C++ code written for g++ would be nearly identical in most circumstances.

How different are they, how often would you say these kinds of issues come up, and do you know of anywhere I can find some of these differences/gotchas?

  • 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-06-17T20:59:49+00:00Added an answer on June 17, 2026 at 8:59 pm

    Different compilers have different headers that internally include other headers. gcc is probably including <string> inside of <iostream>, while Visual Studio’s <iostream> doesn’t include <string>. Try putting:

    #include <string>
    

    At the top with your other includes. <string> is the header file that defines operator>>(std::istream, std::string) (in other words, <string> is the header that “officially” provides the function you need to do std::cin >> str;).

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

Sidebar

Related Questions

Possible Duplicate: Why is List<Number> not a sub-type of List<Object>? Isn't String a subtype
Possible Duplicate: Why isn’t String.Empty a constant? To make my code more readable I
Possible Duplicate: Why isn't the const qualifier working on pointer members on const objects?
Possible Duplicate: Why isn't String.Empty a constant? I can use but not string.Empty when
Possible Duplicate: Why isn't String.Empty a constant? I wanted to use string.Empty in the
Possible Duplicate: Why isn't sizeof for a struct equal to the sum of sizeof
Possible Duplicate: Why isn’t sizeof for a struct equal to the sum of sizeof
Possible Duplicate: What are copy elision and return value optimization? why isn’t the copy
Possible Duplicate: Why isn’t sizeof for a struct equal to the sum of sizeof
Possible Duplicate: Why isn't more Java software compiled natively? I know that Java is

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.