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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:34:37+00:00 2026-06-04T11:34:37+00:00

I have the following function: std::vector<double>residuals; std::cout << Print_res(std::cout); std::ostream& Print_res(std::ostream& os) const {

  • 0

I have the following function:

std::vector<double>residuals;
std::cout << Print_res(std::cout);
std::ostream& Print_res(std::ostream& os) const {

  os << "\tresidual" << std::endl;
  for (unsigned int i = 0 ; i < 22 ; i++) {
    os << "\t\t" << residuals[i] << std::endl;
  }
  os << std::flush;
  return os;
};

It prints the residuals correctly, but at the end of the output tags an address as follows:

2275
2279.08
2224.0835
0x80c5604

how do I fix this?
EDIT: after reading everyone’s comments I replaced the call to the function Print_res with a std::copy as

 std::copy(residuals.begin(), residuals.end(), std::ostream_iterator<double>(std::cout,"\n"));

and that did not print the address, so I presume there is something wrong in the way I have written the function.

  • 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-04T11:34:39+00:00Added an answer on June 4, 2026 at 11:34 am
    std::cout << Print_res(std::cout);
    

    This is not legal at global scope so the code that you have posted is not valid. If this statement were executed from, say, a function then Print_res would be called and then the return value of Print_res would also be streamed to std::cout. This is most likely not what you meant. You probably want just this:

    Print_res(std::cout);
    

    Your statement performs the equivalent of:

    std::cout << std::cout;
    

    In C++03 (which you must be using), std::cout has an operator void* (from std::basic_ios<char>) the result of which is what is being printed.

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

Sidebar

Related Questions

I have the following: typedef std::function<void(const EventArgs&)> event_type; class Event : boost::noncopyable { private:
I have the following function which creates a std::vector of iterators into another container:
Say I have the following: std::vector<int> myints; and then I have a function that
I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)
I have written the following template function for summing the contents of a std::vector
Suppose I have the following function: void foo(std::vector<int> vec, int n); If I call
I have the following code: void Foo() { static std::vector<int>(3); // Vector object is
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>
I have the following template function which prints to cout: template <typename T> void

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.