Given an int variable x write some statements that attempt to open a file named "table20" and read a value into x; if that turns out not to be possible your code should then read avalue from standard input into x.
.
.
Click on the title for the solution
.
.
ifstream filename;
filename.open("table20");
if (filename.fail()){
cin >> x;
}else{
filename >> x;
}
.
Click on the title for the solution
.
.
This is the answer:
:
ifstream filename;
filename.open("table20");
if (filename.fail()){
cin >> x;
}else{
filename >> x;
}
Comments
Post a Comment