В ответ на щедрость @djechlin, поставленную на этот вопрос, я разветвил jsfiddle, отправленный @ matt-h, и пришел к выводу, что это все еще невозможно.
http : //jsfiddle.net/gr3wo9u6/
//this does not work, the frames reload when appended back to the DOM
function swapFrames() {
var w1 = document.getElementById('wrap1');
var w2 = document.getElementById('wrap2');
var f1 = w1.querySelector('iframe');
var f2 = w2.querySelector('iframe');
w1.removeChild(f1);
w2.removeChild(f2);
w1.appendChild(f2);
w2.appendChild(f1);
//f1.parentNode = w2;
//f2.parentNode = w1;
//alert(f1.parentNode.id);
}
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
ifstream file;
ofstream out;
file.open("coinsCoint.txt");
int pennis = 0, nickle = 0, dime = 0, quarter = 0, sum = 0;
float total = 0.0;
/* check if file is opened */
if (file.is_open()){
while (!file.eof())
{
file >> pennis >> nickle >> dime >> quarter;
cout << "pennis " << pennis << endl;
cout << "nickle " << nickle << endl;
cout << "dime " << dime << endl;
cout << "quarter " << quarter << endl;
sum += pennis + nickle * 5 + dime * 10 + quarter * 25;
total = sum / 100.0;
cout << "total " << total;
}
file.close();
}
/* return if error in file open */
else {
cout<< "can not open given file";
return 0;
}
out.open("1234567.txt");
if (out.is_open()){
out << "Total amount collected is: $" << fixed << showpoint <<
setprecision(2) << total;
out.close();
}
return 0;
}
Аналогичное руководство https://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/io/readtextfile.html
Вы должны всегда is_open()
необходимо проверить правильность открытия файла. Для печати «черного экрана» необходимо использовать cout <<
файл выглядит как
1
2
3
4
выход должен быть что-то вроде
pennis 1
nickle 2
dime 3
quarter 4
total 1.41Press <RETURN> to close this window...