Passing an array from txt file to a function
I have a simple function of the form:
double f(double x)
{
...
}
For that function, I want to use data from a txt file, which I pass to an array:
ifstream inFile;
inFile.open("data.txt");
//Counting lines
string s;
int nlines=0;
while(!inFile.eof()){
getline(inFile, s);
nlines++;
}
inFile.seekg(0, ios::beg);
while(!inFile.eof()){
inFile >> a[entry_data];
inFile >> b[entry_data++];
}
inFile.close();
If I put this code inside the function f
, each time the function is called, it will have to open the file, create the array... and so on. I want to avoid this by defining the array just the first time the function is called, or before. How can I do this?
I know that if I define the array in the main scope and pass it to the function as an argument I can solve this, but I want to keep the main scope as clean as possible. Thanks!
c++ arrays function
add a comment |
I have a simple function of the form:
double f(double x)
{
...
}
For that function, I want to use data from a txt file, which I pass to an array:
ifstream inFile;
inFile.open("data.txt");
//Counting lines
string s;
int nlines=0;
while(!inFile.eof()){
getline(inFile, s);
nlines++;
}
inFile.seekg(0, ios::beg);
while(!inFile.eof()){
inFile >> a[entry_data];
inFile >> b[entry_data++];
}
inFile.close();
If I put this code inside the function f
, each time the function is called, it will have to open the file, create the array... and so on. I want to avoid this by defining the array just the first time the function is called, or before. How can I do this?
I know that if I define the array in the main scope and pass it to the function as an argument I can solve this, but I want to keep the main scope as clean as possible. Thanks!
c++ arrays function
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
4
OT but a bug:while(!inFile.eof()){
stackoverflow.com/questions/5605125/…
– drescherjm
Nov 21 '18 at 18:07
1
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know wherea
andb
are declared or allocated.
– drescherjm
Nov 21 '18 at 18:16
1
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17
add a comment |
I have a simple function of the form:
double f(double x)
{
...
}
For that function, I want to use data from a txt file, which I pass to an array:
ifstream inFile;
inFile.open("data.txt");
//Counting lines
string s;
int nlines=0;
while(!inFile.eof()){
getline(inFile, s);
nlines++;
}
inFile.seekg(0, ios::beg);
while(!inFile.eof()){
inFile >> a[entry_data];
inFile >> b[entry_data++];
}
inFile.close();
If I put this code inside the function f
, each time the function is called, it will have to open the file, create the array... and so on. I want to avoid this by defining the array just the first time the function is called, or before. How can I do this?
I know that if I define the array in the main scope and pass it to the function as an argument I can solve this, but I want to keep the main scope as clean as possible. Thanks!
c++ arrays function
I have a simple function of the form:
double f(double x)
{
...
}
For that function, I want to use data from a txt file, which I pass to an array:
ifstream inFile;
inFile.open("data.txt");
//Counting lines
string s;
int nlines=0;
while(!inFile.eof()){
getline(inFile, s);
nlines++;
}
inFile.seekg(0, ios::beg);
while(!inFile.eof()){
inFile >> a[entry_data];
inFile >> b[entry_data++];
}
inFile.close();
If I put this code inside the function f
, each time the function is called, it will have to open the file, create the array... and so on. I want to avoid this by defining the array just the first time the function is called, or before. How can I do this?
I know that if I define the array in the main scope and pass it to the function as an argument I can solve this, but I want to keep the main scope as clean as possible. Thanks!
c++ arrays function
c++ arrays function
asked Nov 21 '18 at 18:03
PsyphyPsyphy
33
33
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
4
OT but a bug:while(!inFile.eof()){
stackoverflow.com/questions/5605125/…
– drescherjm
Nov 21 '18 at 18:07
1
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know wherea
andb
are declared or allocated.
– drescherjm
Nov 21 '18 at 18:16
1
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17
add a comment |
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
4
OT but a bug:while(!inFile.eof()){
stackoverflow.com/questions/5605125/…
– drescherjm
Nov 21 '18 at 18:07
1
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know wherea
andb
are declared or allocated.
– drescherjm
Nov 21 '18 at 18:16
1
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
4
4
OT but a bug:
while(!inFile.eof()){
stackoverflow.com/questions/5605125/…– drescherjm
Nov 21 '18 at 18:07
OT but a bug:
while(!inFile.eof()){
stackoverflow.com/questions/5605125/…– drescherjm
Nov 21 '18 at 18:07
1
1
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know where
a
and b
are declared or allocated.– drescherjm
Nov 21 '18 at 18:16
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know where
a
and b
are declared or allocated.– drescherjm
Nov 21 '18 at 18:16
1
1
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17
add a comment |
2 Answers
2
active
oldest
votes
Let's create an instance that will read your data.
class DataHolder
{
DataHolder()
{
ifstream inFile;
inFile.open("data.txt");
double v1, v2;
while(inFile >> v1 >> v2){
a.push_back(v1);
b.push_back(v2);
}
}
public:
static DataHolder& getInstance()
{
static DataHolder d;
return d;
}
std::vector<double> a, b;
};
Then in your function, use the data holder:
double f(double x)
{
auto& d = DataHolder::getInstance();
// use the holders data
}
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I geterror: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
add a comment |
Your f
function takes 1 (one) value, not an array.
You want to use std::vector<double>
instead of array, if you want to pass the data.
Your loop should be:
double value1, value2;
std::vector<double> a;
std::vector<double> b;
while (inFile >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
You can use your f
function:
const size_t size = a.size();
for (size_t index = 0; index < size; ++size)
{
double result = f(a[index]);
//...
}
Edit 1: Function to Load
You could create an input function and call it once in main
:
void input_data(std::istream& input, std::vector<double>& a, std::vector<double>& b)
{
double value1, value2;
while (input >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
}
I don't think that's what OP wants.a
andb
are read insidef
, not outside.
– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
Also, there is a design smell that the OP should be using aclass
that models the record, instead of using parallel containers.
– Thomas Matthews
Nov 21 '18 at 18:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418081%2fpassing-an-array-from-txt-file-to-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let's create an instance that will read your data.
class DataHolder
{
DataHolder()
{
ifstream inFile;
inFile.open("data.txt");
double v1, v2;
while(inFile >> v1 >> v2){
a.push_back(v1);
b.push_back(v2);
}
}
public:
static DataHolder& getInstance()
{
static DataHolder d;
return d;
}
std::vector<double> a, b;
};
Then in your function, use the data holder:
double f(double x)
{
auto& d = DataHolder::getInstance();
// use the holders data
}
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I geterror: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
add a comment |
Let's create an instance that will read your data.
class DataHolder
{
DataHolder()
{
ifstream inFile;
inFile.open("data.txt");
double v1, v2;
while(inFile >> v1 >> v2){
a.push_back(v1);
b.push_back(v2);
}
}
public:
static DataHolder& getInstance()
{
static DataHolder d;
return d;
}
std::vector<double> a, b;
};
Then in your function, use the data holder:
double f(double x)
{
auto& d = DataHolder::getInstance();
// use the holders data
}
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I geterror: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
add a comment |
Let's create an instance that will read your data.
class DataHolder
{
DataHolder()
{
ifstream inFile;
inFile.open("data.txt");
double v1, v2;
while(inFile >> v1 >> v2){
a.push_back(v1);
b.push_back(v2);
}
}
public:
static DataHolder& getInstance()
{
static DataHolder d;
return d;
}
std::vector<double> a, b;
};
Then in your function, use the data holder:
double f(double x)
{
auto& d = DataHolder::getInstance();
// use the holders data
}
Let's create an instance that will read your data.
class DataHolder
{
DataHolder()
{
ifstream inFile;
inFile.open("data.txt");
double v1, v2;
while(inFile >> v1 >> v2){
a.push_back(v1);
b.push_back(v2);
}
}
public:
static DataHolder& getInstance()
{
static DataHolder d;
return d;
}
std::vector<double> a, b;
};
Then in your function, use the data holder:
double f(double x)
{
auto& d = DataHolder::getInstance();
// use the holders data
}
edited Dec 3 '18 at 22:04
answered Nov 21 '18 at 18:11
Matthieu BrucherMatthieu Brucher
13.4k32140
13.4k32140
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I geterror: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
add a comment |
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I geterror: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
This is what I need. Thank you!
– Psyphy
Nov 21 '18 at 21:15
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I get
error: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
I have been testing your idea, but I can't get it to work. I have tried different variations based on the same idea, but using literally what you have posted I get
error: 'DataHolder' does not refer to a value auto& d = DataHolder.getInstance();
– Psyphy
Dec 3 '18 at 21:35
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
Oops, sorry, it's ::
– Matthieu Brucher
Dec 3 '18 at 22:04
add a comment |
Your f
function takes 1 (one) value, not an array.
You want to use std::vector<double>
instead of array, if you want to pass the data.
Your loop should be:
double value1, value2;
std::vector<double> a;
std::vector<double> b;
while (inFile >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
You can use your f
function:
const size_t size = a.size();
for (size_t index = 0; index < size; ++size)
{
double result = f(a[index]);
//...
}
Edit 1: Function to Load
You could create an input function and call it once in main
:
void input_data(std::istream& input, std::vector<double>& a, std::vector<double>& b)
{
double value1, value2;
while (input >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
}
I don't think that's what OP wants.a
andb
are read insidef
, not outside.
– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
Also, there is a design smell that the OP should be using aclass
that models the record, instead of using parallel containers.
– Thomas Matthews
Nov 21 '18 at 18:19
add a comment |
Your f
function takes 1 (one) value, not an array.
You want to use std::vector<double>
instead of array, if you want to pass the data.
Your loop should be:
double value1, value2;
std::vector<double> a;
std::vector<double> b;
while (inFile >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
You can use your f
function:
const size_t size = a.size();
for (size_t index = 0; index < size; ++size)
{
double result = f(a[index]);
//...
}
Edit 1: Function to Load
You could create an input function and call it once in main
:
void input_data(std::istream& input, std::vector<double>& a, std::vector<double>& b)
{
double value1, value2;
while (input >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
}
I don't think that's what OP wants.a
andb
are read insidef
, not outside.
– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
Also, there is a design smell that the OP should be using aclass
that models the record, instead of using parallel containers.
– Thomas Matthews
Nov 21 '18 at 18:19
add a comment |
Your f
function takes 1 (one) value, not an array.
You want to use std::vector<double>
instead of array, if you want to pass the data.
Your loop should be:
double value1, value2;
std::vector<double> a;
std::vector<double> b;
while (inFile >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
You can use your f
function:
const size_t size = a.size();
for (size_t index = 0; index < size; ++size)
{
double result = f(a[index]);
//...
}
Edit 1: Function to Load
You could create an input function and call it once in main
:
void input_data(std::istream& input, std::vector<double>& a, std::vector<double>& b)
{
double value1, value2;
while (input >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
}
Your f
function takes 1 (one) value, not an array.
You want to use std::vector<double>
instead of array, if you want to pass the data.
Your loop should be:
double value1, value2;
std::vector<double> a;
std::vector<double> b;
while (inFile >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
You can use your f
function:
const size_t size = a.size();
for (size_t index = 0; index < size; ++size)
{
double result = f(a[index]);
//...
}
Edit 1: Function to Load
You could create an input function and call it once in main
:
void input_data(std::istream& input, std::vector<double>& a, std::vector<double>& b)
{
double value1, value2;
while (input >> value1 >> value2)
{
a.push_back(value1);
b.push_back(value2);
}
}
edited Nov 21 '18 at 18:13
answered Nov 21 '18 at 18:10
Thomas MatthewsThomas Matthews
44.2k1173122
44.2k1173122
I don't think that's what OP wants.a
andb
are read insidef
, not outside.
– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
Also, there is a design smell that the OP should be using aclass
that models the record, instead of using parallel containers.
– Thomas Matthews
Nov 21 '18 at 18:19
add a comment |
I don't think that's what OP wants.a
andb
are read insidef
, not outside.
– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
Also, there is a design smell that the OP should be using aclass
that models the record, instead of using parallel containers.
– Thomas Matthews
Nov 21 '18 at 18:19
I don't think that's what OP wants.
a
and b
are read inside f
, not outside.– Matthieu Brucher
Nov 21 '18 at 18:13
I don't think that's what OP wants.
a
and b
are read inside f
, not outside.– Matthieu Brucher
Nov 21 '18 at 18:13
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
To me it's not 100% clear what the OP wants.
– drescherjm
Nov 21 '18 at 18:14
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
Basically the function uses a bunch of parameters that are in a file, and OP doesn't want to load them each time the function is called.
– Matthieu Brucher
Nov 21 '18 at 18:15
1
1
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
This gives the OP some tools to work with. I don't like giving 100% solutions, I like to make the posters think.
– Thomas Matthews
Nov 21 '18 at 18:16
1
1
Also, there is a design smell that the OP should be using a
class
that models the record, instead of using parallel containers.– Thomas Matthews
Nov 21 '18 at 18:19
Also, there is a design smell that the OP should be using a
class
that models the record, instead of using parallel containers.– Thomas Matthews
Nov 21 '18 at 18:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418081%2fpassing-an-array-from-txt-file-to-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Wrap your function in a class, and use a singleton there to get the data you want.
– Matthieu Brucher
Nov 21 '18 at 18:05
4
OT but a bug:
while(!inFile.eof()){
stackoverflow.com/questions/5605125/…– drescherjm
Nov 21 '18 at 18:07
1
Why are you counting the lines?! Total waste of electrons.
– n.m.
Nov 21 '18 at 18:15
My guess is the OP can't use std::vector. That is not at all clear since the line count is not used and we don't know where
a
andb
are declared or allocated.– drescherjm
Nov 21 '18 at 18:16
1
@drescherjm cannot use vector but can use seekg? Found an idiot professor.
– n.m.
Nov 21 '18 at 18:17