Developer forums (C::B DEVELOPMENT STRICTLY!) > Contributions to C::B
Read Input from a File
andrew:
You can use argument like in c++
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
if (argc == 1) {
cerr << "Useing: " << argv[0] << " filename\n";
exit(1); //EXIT_FAILURE
}
ifstream fin;
long count;
long total = 0;
char ch;
for (int file = 1 ; file < argc; file++) {
fin.open(argv[file]); // open all files we see
// cout << argv[file] << endl;
if (!fin.is_open()) {
cerr << "Cannot open file " << argv[file] << endl;
fin.clear();
// continue;
}
// cout << argv[file] << endl;
count = 0;
while (fin.get(ch))
count++;
cout << count << " simbols in " << argv[file] << endl ;
total += count;
fin.clear();
fin.close();
}
cout << total << " simbols in all files\n";
return 0;
}
//---------------------------------------------------------------------------
Navigation
[0] Message Index
[*] Previous page
Go to full version