#include <fstream>
#include<iostream>
using namespace std;
int main() {
ifstream infile; // unbound input file stream
ofstream outfile; // unbound output file stream
string filename("C:/01liwenjie/C++/test.cpp");
string outFileName("D:/01liwenjie/C++/out.txt");
infile.open(filename.c_str());
outfile.open(outFileName.c_str());
if (!infile) {
cerr << "error: unable to open input file: "
<< filename.c_str() << endl;
} else {
cout << "ok: successfully open input file: "
<< filename.c_str() << endl;
}
if (!outfile) {
cerr << "error: unable to open out file: "
<< outFileName.c_str() << endl;
} else {
cout << "ok: successfully open out file: "
<< outFileName.c_str() << endl;
}
/*
*/
/**
*
*
*/
infile.close();
infile.open("CPPPrimer.pdf");
int sum = 0, val = 1;
while (val <= 10) {
sum += val;
++val;
}
cout << "Sum of 1 to 10 inclusive is " << sum << endl;
sum = 0;
for (int val = 2; val <= 11; val++) {
sum = sum + val;
}
cout << "Sum of 2 to 11 inclusive is " << sum << endl;
//infile.open("out.txt");
cout << "Enter numbers: " << endl;
int num = 0;
int cnt = 0;
while (cin >> num) {
if (num < 0) {
cout << num << " < 0" << endl;
cnt++;
}
}
cout << "The count of number which < 0 is: " << cnt << endl;
return -1;
}
C++学习代码--fileTest
最新推荐文章于 2022-08-23 22:37:21 发布