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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:55:16+00:00 2026-05-19T15:55:16+00:00

I cannot understand why my compiler (MSVC++2010) doesn’t like this code: // get_sum(filename as

  • 0

I cannot understand why my compiler (MSVC++2010) doesn’t like this code:

    // get_sum(filename as c-string) returns sum from file
    int get_sum(const char* const s) {
        stringbuf bill_buf;
        ifstream bill_file;
        bill_file.open(s);
        bill_file.get(bill_buf, '\0');  // read whole file
        bill_file.close();
        return get_sum_from_string(bill_buf.str());
}

I get these errors (I translated them from German to English and give the correct line numbers for the code excerpt without leading comment):

  1. Error 1 error C2079: ‘bill_buf’ uses undefined class ‘std::basic_stringbuf<_Elem,_Traits,_Alloc>’ (Line 2)

  2. Error 2 error C2664: ‘std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)’: Conversion of parameter 1 from ‘int’ to ‘char *’ not possible (Line 5)

  3. Error 3 error C2228: To the left of “.str” there must be a class/structure/union. (Line 7)

Has anyone got an idea what’s going on there? Thanks a lot! (If anyone has got a better idea how to quickly get the whole file contents into a string, I’d also appreciate it)

  • 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-19T15:55:17+00:00Added an answer on May 19, 2026 at 3:55 pm

    You’re missing an include. Here’s your code, this time without using streambuf:

    #include<fstream>
    #include<string>
    #include<iterator>
    
    int get_sum(const char* const s) {
        std::ifstream bill_file(s);
        std::string contents((std::istreambuf_iterator<char>(bill_file)),
                             std::istreambuf_iterator<char>());
        return get_sum_from_string(contents);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot understand why this piece of code does not compile: namespace A {
I cannot understand how this is possible. Please help!! I have an app with
For the life of me I cannot understand why the compiler won't let me
In C#, the following code doesn't compile: class Foo { public string Foo; }
I cannot understand the Oracle documentation. :-( Does anybody know how to fetch multiple
The question is simple: I cannot understand the Zipper data structure. My question is
Maybe it's just me, but I cannot understand the documentation regarding Junit test integration
I noticed that there is one change about ASP.NET Routing. I cannot understand why
I cannot get a two-way bind in WPF to work. I have a string
There is something that I cannot understand in C#. You can cast an out-of-range

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.