Read file to istream replacing class variables
I understand how to implement a overloaded ostream operator but I'm a little confused on a overloaded istream operator. All the examples online only show a brief demonstration (i.e. is >> val; ) which doesn't help me in context with my class variables and methods. In my main, I'm trying to read in a file and replace the pointers contents with the file contents. I have a factory method and read method that does that already but I'm trying to overload my istream operator to do the same. However, although the pointers contents are replaced, I still receive the cerr message below. Am I supposed to pass something to the ifs in my >> function?
Here is my main
int main() {
// factory method instantiates all class variables
Base *aa = Base::create(file); // it works
ifstream in(file2);
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
cout << *aa; // prints vector contents
}
Prints
// file // file2 cout << *aa SupposedToBe
555 111 Read Failed 111
555 222 111 222
555 333 222 333
333
What I have so far (.cpp)
istream &operator>>(istream &ifs, Base &val) {
string line;
getline(ifs, line); // type of file
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
// read remaining contents
while(getline(ifs, line)) {
for(size_t i = 0; i < line.length(); i++)
inner.push_back(line[i]);
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
My overloaded ostream function looks a lot different that what is displayed above (i.e. lots of os << value). But, whenever I do ifs >> value, I get all kinds of compiler errors (i.e. I tried just doing ifs >> val.image; ifs >> val.height; etc. but all I got was compiler errors). What am I supposed to pass to the istream (in the above function) so the error above (below main) doesn't display.
.h file for reference
class Base
{
protected:
std::vector<std::vector<int> > vec;
std::string filetype;
int width, height, max;
Base() = default;
Base &operator=(const Base &) = default;
public:
static Base* create(std::string filename);
virtual ~Base();
// read by derived class
virtual void read(std::string filename) = 0;
friend std::istream &operator>>(std::istream &, Base &);
friend std::ostream &operator<<(std::ostream &, const Image &);
};
c++ istream
add a comment |
I understand how to implement a overloaded ostream operator but I'm a little confused on a overloaded istream operator. All the examples online only show a brief demonstration (i.e. is >> val; ) which doesn't help me in context with my class variables and methods. In my main, I'm trying to read in a file and replace the pointers contents with the file contents. I have a factory method and read method that does that already but I'm trying to overload my istream operator to do the same. However, although the pointers contents are replaced, I still receive the cerr message below. Am I supposed to pass something to the ifs in my >> function?
Here is my main
int main() {
// factory method instantiates all class variables
Base *aa = Base::create(file); // it works
ifstream in(file2);
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
cout << *aa; // prints vector contents
}
Prints
// file // file2 cout << *aa SupposedToBe
555 111 Read Failed 111
555 222 111 222
555 333 222 333
333
What I have so far (.cpp)
istream &operator>>(istream &ifs, Base &val) {
string line;
getline(ifs, line); // type of file
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
// read remaining contents
while(getline(ifs, line)) {
for(size_t i = 0; i < line.length(); i++)
inner.push_back(line[i]);
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
My overloaded ostream function looks a lot different that what is displayed above (i.e. lots of os << value). But, whenever I do ifs >> value, I get all kinds of compiler errors (i.e. I tried just doing ifs >> val.image; ifs >> val.height; etc. but all I got was compiler errors). What am I supposed to pass to the istream (in the above function) so the error above (below main) doesn't display.
.h file for reference
class Base
{
protected:
std::vector<std::vector<int> > vec;
std::string filetype;
int width, height, max;
Base() = default;
Base &operator=(const Base &) = default;
public:
static Base* create(std::string filename);
virtual ~Base();
// read by derived class
virtual void read(std::string filename) = 0;
friend std::istream &operator>>(std::istream &, Base &);
friend std::ostream &operator<<(std::ostream &, const Image &);
};
c++ istream
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.
– Neil Butterworth
Nov 21 '18 at 23:01
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04
add a comment |
I understand how to implement a overloaded ostream operator but I'm a little confused on a overloaded istream operator. All the examples online only show a brief demonstration (i.e. is >> val; ) which doesn't help me in context with my class variables and methods. In my main, I'm trying to read in a file and replace the pointers contents with the file contents. I have a factory method and read method that does that already but I'm trying to overload my istream operator to do the same. However, although the pointers contents are replaced, I still receive the cerr message below. Am I supposed to pass something to the ifs in my >> function?
Here is my main
int main() {
// factory method instantiates all class variables
Base *aa = Base::create(file); // it works
ifstream in(file2);
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
cout << *aa; // prints vector contents
}
Prints
// file // file2 cout << *aa SupposedToBe
555 111 Read Failed 111
555 222 111 222
555 333 222 333
333
What I have so far (.cpp)
istream &operator>>(istream &ifs, Base &val) {
string line;
getline(ifs, line); // type of file
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
// read remaining contents
while(getline(ifs, line)) {
for(size_t i = 0; i < line.length(); i++)
inner.push_back(line[i]);
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
My overloaded ostream function looks a lot different that what is displayed above (i.e. lots of os << value). But, whenever I do ifs >> value, I get all kinds of compiler errors (i.e. I tried just doing ifs >> val.image; ifs >> val.height; etc. but all I got was compiler errors). What am I supposed to pass to the istream (in the above function) so the error above (below main) doesn't display.
.h file for reference
class Base
{
protected:
std::vector<std::vector<int> > vec;
std::string filetype;
int width, height, max;
Base() = default;
Base &operator=(const Base &) = default;
public:
static Base* create(std::string filename);
virtual ~Base();
// read by derived class
virtual void read(std::string filename) = 0;
friend std::istream &operator>>(std::istream &, Base &);
friend std::ostream &operator<<(std::ostream &, const Image &);
};
c++ istream
I understand how to implement a overloaded ostream operator but I'm a little confused on a overloaded istream operator. All the examples online only show a brief demonstration (i.e. is >> val; ) which doesn't help me in context with my class variables and methods. In my main, I'm trying to read in a file and replace the pointers contents with the file contents. I have a factory method and read method that does that already but I'm trying to overload my istream operator to do the same. However, although the pointers contents are replaced, I still receive the cerr message below. Am I supposed to pass something to the ifs in my >> function?
Here is my main
int main() {
// factory method instantiates all class variables
Base *aa = Base::create(file); // it works
ifstream in(file2);
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
cout << *aa; // prints vector contents
}
Prints
// file // file2 cout << *aa SupposedToBe
555 111 Read Failed 111
555 222 111 222
555 333 222 333
333
What I have so far (.cpp)
istream &operator>>(istream &ifs, Base &val) {
string line;
getline(ifs, line); // type of file
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
// read remaining contents
while(getline(ifs, line)) {
for(size_t i = 0; i < line.length(); i++)
inner.push_back(line[i]);
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
My overloaded ostream function looks a lot different that what is displayed above (i.e. lots of os << value). But, whenever I do ifs >> value, I get all kinds of compiler errors (i.e. I tried just doing ifs >> val.image; ifs >> val.height; etc. but all I got was compiler errors). What am I supposed to pass to the istream (in the above function) so the error above (below main) doesn't display.
.h file for reference
class Base
{
protected:
std::vector<std::vector<int> > vec;
std::string filetype;
int width, height, max;
Base() = default;
Base &operator=(const Base &) = default;
public:
static Base* create(std::string filename);
virtual ~Base();
// read by derived class
virtual void read(std::string filename) = 0;
friend std::istream &operator>>(std::istream &, Base &);
friend std::ostream &operator<<(std::ostream &, const Image &);
};
c++ istream
c++ istream
edited Nov 21 '18 at 23:31
N. Colostate
asked Nov 21 '18 at 22:56
N. ColostateN. Colostate
356
356
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.
– Neil Butterworth
Nov 21 '18 at 23:01
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04
add a comment |
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.
– Neil Butterworth
Nov 21 '18 at 23:01
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.– Neil Butterworth
Nov 21 '18 at 23:01
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.– Neil Butterworth
Nov 21 '18 at 23:01
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04
add a comment |
1 Answer
1
active
oldest
votes
Use of
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
is a problem. The way you have implemenented operator>>(std::istream &, Base &)
, that logic is bound to fail every time.
You have a loop in the function
while(getline(ifs, line)) {
...
}
That loop will break only when there is nothing to read from the file or there is an error in reading the contents of the file. When that loop exits, ifs.fail()
will always be true.
You should replace the if
statement with just:
in >> *aa;
If you need to do any error checking and print appropriate error messages, that has to be done inside operator>>(std::istream &, Base &)
.
Update, in response to OP's comment
One way to make sure that the istream
does not get to the point where ifs.fail()
is always true
is to know what's expected ahead of time.
If the number of lines expected in the file is the first input, then, it is possible to read all the data and return from the function such that ifs.fail()
is false
.
Sample input:
type1
3
111
222
333
Then, the oprator>>
function can be defined as:
std::stream& operator>>(std::istream& ifs, Base& val)
{
std::string line;
if ( !getline(ifs, line) ) // type of file
{
// Problem reading. No point trying to read more.
return ifs;
}
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
// read remaining contents
int numLines = 0;
if ( !(ifs >> numLines) )
{
// Problem reading. No point trying to read more.
return ifs;
}
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
for ( int n = 0; n < numLines; ++n )
{
if ( !getline(ifs, line))
{
// Problem reading. No point trying to read more.
return ifs;
}
for(size_t i = 0; i < line.length(); i++)
{
inner.push_back(line[i]);
}
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
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%2f53421600%2fread-file-to-istream-replacing-class-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use of
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
is a problem. The way you have implemenented operator>>(std::istream &, Base &)
, that logic is bound to fail every time.
You have a loop in the function
while(getline(ifs, line)) {
...
}
That loop will break only when there is nothing to read from the file or there is an error in reading the contents of the file. When that loop exits, ifs.fail()
will always be true.
You should replace the if
statement with just:
in >> *aa;
If you need to do any error checking and print appropriate error messages, that has to be done inside operator>>(std::istream &, Base &)
.
Update, in response to OP's comment
One way to make sure that the istream
does not get to the point where ifs.fail()
is always true
is to know what's expected ahead of time.
If the number of lines expected in the file is the first input, then, it is possible to read all the data and return from the function such that ifs.fail()
is false
.
Sample input:
type1
3
111
222
333
Then, the oprator>>
function can be defined as:
std::stream& operator>>(std::istream& ifs, Base& val)
{
std::string line;
if ( !getline(ifs, line) ) // type of file
{
// Problem reading. No point trying to read more.
return ifs;
}
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
// read remaining contents
int numLines = 0;
if ( !(ifs >> numLines) )
{
// Problem reading. No point trying to read more.
return ifs;
}
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
for ( int n = 0; n < numLines; ++n )
{
if ( !getline(ifs, line))
{
// Problem reading. No point trying to read more.
return ifs;
}
for(size_t i = 0; i < line.length(); i++)
{
inner.push_back(line[i]);
}
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
add a comment |
Use of
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
is a problem. The way you have implemenented operator>>(std::istream &, Base &)
, that logic is bound to fail every time.
You have a loop in the function
while(getline(ifs, line)) {
...
}
That loop will break only when there is nothing to read from the file or there is an error in reading the contents of the file. When that loop exits, ifs.fail()
will always be true.
You should replace the if
statement with just:
in >> *aa;
If you need to do any error checking and print appropriate error messages, that has to be done inside operator>>(std::istream &, Base &)
.
Update, in response to OP's comment
One way to make sure that the istream
does not get to the point where ifs.fail()
is always true
is to know what's expected ahead of time.
If the number of lines expected in the file is the first input, then, it is possible to read all the data and return from the function such that ifs.fail()
is false
.
Sample input:
type1
3
111
222
333
Then, the oprator>>
function can be defined as:
std::stream& operator>>(std::istream& ifs, Base& val)
{
std::string line;
if ( !getline(ifs, line) ) // type of file
{
// Problem reading. No point trying to read more.
return ifs;
}
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
// read remaining contents
int numLines = 0;
if ( !(ifs >> numLines) )
{
// Problem reading. No point trying to read more.
return ifs;
}
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
for ( int n = 0; n < numLines; ++n )
{
if ( !getline(ifs, line))
{
// Problem reading. No point trying to read more.
return ifs;
}
for(size_t i = 0; i < line.length(); i++)
{
inner.push_back(line[i]);
}
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
add a comment |
Use of
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
is a problem. The way you have implemenented operator>>(std::istream &, Base &)
, that logic is bound to fail every time.
You have a loop in the function
while(getline(ifs, line)) {
...
}
That loop will break only when there is nothing to read from the file or there is an error in reading the contents of the file. When that loop exits, ifs.fail()
will always be true.
You should replace the if
statement with just:
in >> *aa;
If you need to do any error checking and print appropriate error messages, that has to be done inside operator>>(std::istream &, Base &)
.
Update, in response to OP's comment
One way to make sure that the istream
does not get to the point where ifs.fail()
is always true
is to know what's expected ahead of time.
If the number of lines expected in the file is the first input, then, it is possible to read all the data and return from the function such that ifs.fail()
is false
.
Sample input:
type1
3
111
222
333
Then, the oprator>>
function can be defined as:
std::stream& operator>>(std::istream& ifs, Base& val)
{
std::string line;
if ( !getline(ifs, line) ) // type of file
{
// Problem reading. No point trying to read more.
return ifs;
}
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
// read remaining contents
int numLines = 0;
if ( !(ifs >> numLines) )
{
// Problem reading. No point trying to read more.
return ifs;
}
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
for ( int n = 0; n < numLines; ++n )
{
if ( !getline(ifs, line))
{
// Problem reading. No point trying to read more.
return ifs;
}
for(size_t i = 0; i < line.length(); i++)
{
inner.push_back(line[i]);
}
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
Use of
if((in >> *aa).fail()) // Read file contents
cerr << "Read failed" << 'n';
is a problem. The way you have implemenented operator>>(std::istream &, Base &)
, that logic is bound to fail every time.
You have a loop in the function
while(getline(ifs, line)) {
...
}
That loop will break only when there is nothing to read from the file or there is an error in reading the contents of the file. When that loop exits, ifs.fail()
will always be true.
You should replace the if
statement with just:
in >> *aa;
If you need to do any error checking and print appropriate error messages, that has to be done inside operator>>(std::istream &, Base &)
.
Update, in response to OP's comment
One way to make sure that the istream
does not get to the point where ifs.fail()
is always true
is to know what's expected ahead of time.
If the number of lines expected in the file is the first input, then, it is possible to read all the data and return from the function such that ifs.fail()
is false
.
Sample input:
type1
3
111
222
333
Then, the oprator>>
function can be defined as:
std::stream& operator>>(std::istream& ifs, Base& val)
{
std::string line;
if ( !getline(ifs, line) ) // type of file
{
// Problem reading. No point trying to read more.
return ifs;
}
if(line == "type1")
val.filetype = "type1";
if(line == "type2")
val.filetype = "type2";
// read remaining contents
int numLines = 0;
if ( !(ifs >> numLines) )
{
// Problem reading. No point trying to read more.
return ifs;
}
val.vec.clear(); // clear old vector
vector<int> inner; // inner vec to push onto main vec
for ( int n = 0; n < numLines; ++n )
{
if ( !getline(ifs, line))
{
// Problem reading. No point trying to read more.
return ifs;
}
for(size_t i = 0; i < line.length(); i++)
{
inner.push_back(line[i]);
}
val.vec.push_back(inner);
inner.clear();
}
val.height = val.vec.size();
val.width = val.vec[0].size();
val.max = val.vec[height-1][width-1];
return ifs;
}
edited Nov 22 '18 at 4:07
answered Nov 21 '18 at 23:09
R SahuR Sahu
167k1292190
167k1292190
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
add a comment |
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Is there a way to fix my logic in my operator>> function so that it doesn't fail? in >> *aa; works without error, but I need to use the if-statement you highlighted in your response.
– N. Colostate
Nov 21 '18 at 23:26
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
Yes. The full response I have in mind is lengthy and I can't get to it for a few hours.
– R Sahu
Nov 21 '18 at 23:38
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%2f53421600%2fread-file-to-istream-replacing-class-variables%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
Base *aa = Base::create(file);
- don't do that - no need to use a pointer.– Neil Butterworth
Nov 21 '18 at 23:01
To be a real complete example, we also need your input file please.
– Christopher Pisz
Nov 21 '18 at 23:02
I added it. It's below main.
– N. Colostate
Nov 21 '18 at 23:04