Code::Blocks Forums
Developer forums (C::B DEVELOPMENT STRICTLY!) => Contributions to C::B => Topic started by: dedachi on March 03, 2010, 05:07:39 pm
-
Hello,
Consider I have a program which has to get input from a file containing some data.
In gcc, the indirection/redirection operators work.
So I would do:
./a.out < readfromFile.txt and values from a txt file will be read into the program.
I am confused how could I do this using codeblocks?
Please advise.
Thanks
-
You can't if I remember correctly.
You should start your program in terminal
-
I am confused how could I do this using codeblocks?
You can use the tool menu for that.
Setup a tool that uses the appropriate macros to point to your application which is being piped into a batch file or alike.
-
You can't if I remember correctly.
You should start your program in terminal
Please can you give an example of this?
-
I am confused how could I do this using codeblocks?
You can use the tool menu for that.
Setup a tool that uses the appropriate macros to point to your application which is being piped into a batch file or alike.
Sorry, I am new to codeblocks.
Can you please explain further or supply an example?
Thanks!
-
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;
}
//---------------------------------------------------------------------------