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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:12:08+00:00 2026-06-13T08:12:08+00:00

I am implementing a template function to read a file and file-like entities into

  • 0

I am implementing a template function to read a file and file-like entities into a vector line by line:

#include <iostream>
#include <vector>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <fstream>
using namespace std;
template<typename T> vector<T> readfile(T ref1)
{
    std::vector<T> vec;
    std::istream_iterator<T> is_i;
    std::ifstream file(ref1);
    std::copy(is_i(file), is_i(), std::back_inserter(vec));
    return vec;
}

I look to read a file using the following code in main:

int main()
{
    std::string t{"example.txt"};
    std::vector<std::string> a = readfile(t);
    return 0;
}

I get the error:
“no match for call to ‘(std::istream_iterator, char, …

Let me know if I need to supply more of the error message. Chances are I am just messing up something simple. But I can’t understand why – using tutorials I have gotten this and I thought it to be a pretty good solution.

  • 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-13T08:12:09+00:00Added an answer on June 13, 2026 at 8:12 am

    You apparently meant to turn is_i into a type but instead declared a variable of type std_istream_iterator<T>. You probably meant to write:

    typedef std::istream_iterator<T> is_i;
    

    You should probably also decouple your template argument from the type used for the file name as the template is otherwise fairly restrictive:

    template <typename T>
    std::vector<T> readfile(std::string const& name) {
        ...
    }
    
    std::vector<int> values = readfile<int>("int-values");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my code for implementing HeapTree #include<iostream> #include<assert.h> using namespace std; template <class
Please consider the following code: #include <iostream> #include <typeinfo> template< typename Type > void
I've been implementing a custom template matrix class and I have a function I
I'm implementing a template function which sets the values of the first n elements
I'm implementing a new template for a Magento site. I have issues with categories
For my compsci class, I am implementing a Stack template class, but have run
Hi i added template field dynamically to gridview by implementing ITemplate interface. The template
I have a small template that ive built for the purpose of implementing an
I have a function where I have a container which holds strings (eg vector<string>
I am implementing the Merge sort algorithm. The problem is when I try to

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.