Use a std::string rather than a char pointer to convey the file name.

This commit is contained in:
Bård Skaflestad 2011-12-02 19:07:35 +01:00
parent e6638e3892
commit 17228b7078
2 changed files with 10 additions and 6 deletions

View File

@ -18,6 +18,8 @@
#include <vector> #include <vector>
#include "readvector.hpp"
struct ParserState { struct ParserState {
int error; int error;
}; };
@ -260,21 +262,21 @@ static char *convert_string(double *value, char *str)
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
template <typename T> template <typename T>
void read_vector_from_file(const char *fn, std::vector<T>& v) void read_vector_from_file(const std::string& fn, std::vector<T>& v)
{ {
FILE *fp = fopen(fn, "r"); FILE *fp = fopen(fn.c_str(), "r");
struct ParserState s = { 0 }; struct ParserState s = { 0 };
readvector(fp, &s, v); readvector(fp, &s, v);
fclose(fp); fclose(fp);
} }
void read_vector_from_file(const char *fn, std::vector<int>& v) void read_vector_from_file(const std::string& fn, std::vector<int>& v)
{ {
read_vector_from_file<int>(fn, v); read_vector_from_file<int>(fn, v);
} }
void read_vector_from_file(const char *fn, std::vector<double>& v) void read_vector_from_file(const std::string& fn, std::vector<double>& v)
{ {
read_vector_from_file<double>(fn, v); read_vector_from_file<double>(fn, v);
} }

View File

@ -16,7 +16,9 @@
#ifndef READVECTOR_HPP_HEADER #ifndef READVECTOR_HPP_HEADER
#define READVECTOR_HPP_HEADER #define READVECTOR_HPP_HEADER
void read_vector_from_file(const char *fn, std::vector<int>& v); #include <string>
void read_vector_from_file(const char *fn, std::vector<double>& v);
void read_vector_from_file(const std::string&, std::vector<int>& v);
void read_vector_from_file(const std::string&, std::vector<double>& v);
#endif /* READVECTOR_HPP_HEADER */ #endif /* READVECTOR_HPP_HEADER */