read file into vector
std::vector<char> vec;
if (FILE *fp = fopen("filename", "r"))
{
char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), fp))
{
v.insert(vec.end(), buf, buf + len);
}
fclose(fp);
}
read file into vector
std::vector<char> vec;
if (FILE *fp = fopen("filename", "r"))
{
char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), fp))
{
v.insert(vec.end(), buf, buf + len);
}
fclose(fp);
}
c++ load file as vector
#include <iostream>
#include <iterator>
#include <fstream>
#include <vector>
#include <algorithm> // for std::copy
int main()
{
std::ifstream is("numbers.txt");
std::istream_iterator<double> start(is), end;
std::vector<double> numbers(start, end);
std::cout << "Read " << numbers.size() << " numbers" << std::endl;
// print the numbers to stdout
std::cout << "numbers read in:\n";
std::copy(numbers.begin(), numbers.end(),
std::ostream_iterator<double>(std::cout, " "));
std::cout << std::endl;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us