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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:43:54+00:00 2026-06-10T19:43:54+00:00

I convert this code in python to c++: content = file(filename, rb).read() this is

  • 0

I convert this code in python to c++:

content = file(filename, "rb").read()

this is the code in c++:

ifstream file;
file.open(filename, fstream::binary);

file.seekg (0, ios::end);
long fileLength = file.tellg();
file.seekg(0, ios_base::beg);

char *content = new char[fileLength];
file.read(content, fileLength);

when I run the python code I get a long string in the content (500 characters~) while the c++ code return only 4 characters.

any suggestion?

thanks

  • 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-10T19:43:56+00:00Added an answer on June 10, 2026 at 7:43 pm

    The simplest way to read an entire file is:

    std::string content(
        std::istreambuf_iterator<char>(std::ifstream(filename, std::fstream::binary).rdbuf()),
        std::istreambuf_iterator<char>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have the Python code: someString = file(filename.jpg).read() How can I replicate
I want to convert vb this code <?php // Where the file is going
I'm converting some c code to python. Can someone convert this for loop from
I wrote this python code in an attempt to convert objects to a string
I'm trying to convert this Python code to C. But for the life of
I'm trying to convert this C# code to Python (2.5, GAE). The problem is
How can I convert this code from C# to Python to be run on
I am new to Python and want convert this small JavaScript code to Python.
I'm trying to convert some Ruby code into Python. I'm having troubles with this
I want to convert this C++ code to Python v2: static unsigned char asConvCode[3]

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.