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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:21:24+00:00 2026-06-07T11:21:24+00:00

I tried to write stream.rdbuf() to a file but it doesn’t seem to work,

  • 0

I tried to write stream.rdbuf() to a file but it doesn’t seem to work, just a blank file, I don`t know what to do.

#include "stdafx.h"

#include <iostream>
#include <boost/asio.hpp>
#include <conio.h>
#include <stdio.h>
#include <fstream>

char buffer [9999999];

int main()
{
    boost::asio::ip::tcp::iostream stream;
    stream.expires_from_now(boost::posix_time::seconds(60));
    stream.connect("www.mail.ru","http");
    stream << "GET / HTTP/1.1\r\n";
    stream << "Host mail.ru\r\n";
    stream << "User-Agent   Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11\r\n";
    stream << "Accept   text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" ;
    stream << "Accept-Encoding  gzip,deflate,sdch\r\n";
    stream << "Accept-Language  en-US,en;q=0.8\r\n";
    stream <<"Accept-Charset    ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n";
    stream << "Cookie   \r\n\r\n";
    stream.flush();
    using namespace std ;
    cout << stream.rdbuf();
    ofstream f("output.txt" /*| ios::bin*/);
    f << stream.rdbuf();
    f.close();
    system("pause");
    return 0 ;
}
  • 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-07T11:21:26+00:00Added an answer on June 7, 2026 at 11:21 am

    You are invoking stream.rdbuf() twice: once for the standard out cout and then for the file.

    It is unclear from your explanation whether you see anything outputed on the screen (when you write to cout).

    1) If yes, you need to write that to the file instead: by the time you read the stream again, it is exhausted and does not contain anything.

    Just remove the

    cout << stream.rdbuf(); 
    

    line.

    If you need to see the result on the screen as well, capture it in a std::stringstream first, then you can output its content to both the screen and the file (use seekp on the stringstream to reset it after the first extraction)

    2) If you do not see the results on the screen, you most likely have a problem with connecting to the service

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

Sidebar

Related Questions

I don't know why this is erroring, but I'm just trying to add something
I tried to write a Neural Network system, but even running through simple AND/OR/NOR
I tried to write a program that uses threads, but couldn't understand the o/p.
I tried to write a Taylor series expansion for exp(x)/sin(x) using fortran, but when
I tried this function to convert a string to _int64 but it didn't work
Is it possible to use java to write into a webcam stream? I've tried
i'm trying to write an application to stream videos like SipDroid, but SipDroid only
What is the best way to read amnd write and IO.Stream (Zip file downloded
I tried to write a function to check key code with JavaScript. It's working
I tried to write a script to list all files in directories and subdirectories

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.