Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a counter 1

Status
Not open for further replies.

ojosVerdes

Technical User
Oct 10, 2002
50
US
I have a program that manipulates records read from a text file. This program has a counter, and I display the counter by using cout << lngCnt;

I run this program from the command line is DOS based.

However the result I get are 123456789101112...
I get the first record, then on the same line a get 2, right next to the one, and then 3 and next to the 2 and so on.

I tryed using cout << lngCnt << endl; but that put a line after each record displayed.

how can I make the counter stay(display) in the same place?
Is this possible?

Thanks in advance.

Ed.

 
That did it. Thanks

How about this. I have the following program. see the 7th or 8th line, where it opens the &quot;input.txt&quot; file. how can I pass this file as a parameter to the program?

The name of the file can be anything?

Please help.

Thanks.


#include <set>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
ifstream infile(&quot;input.txt&quot;);
istream fin(infile);
string strReadIn;
string strBatch;
int intBL;
set<string> batch_set; //instantiate set container
while(getline(fin, strReadIn))
{
if(strReadIn.size() < 200)
continue;
if(strReadIn.substr(154, 1) == &quot;H&quot;)
{
strBatch = strReadIn.substr(154, 16);
intBL = 16;
batch_set.insert(strReadIn); //attempt insert
}
else if(strReadIn.substr(154, 3) == &quot;SME&quot;)
{
strBatch = strReadIn.substr(154, 19);
intBL = 19;
batch_set.insert(strReadIn);
}
else if(strReadIn.substr(154, 3) == &quot;DSI&quot;)
{
strBatch = strReadIn.substr(154, 19);
intBL = 19;
batch_set.insert(strBatch);
}
else if(strReadIn.substr(154, 5) == &quot;00000&quot;)
{
strBatch = strReadIn.substr(154, 25);
intBL = 25;
batch_set.insert(strReadIn);
}
}
cout << &quot;Number of batches found is &quot; << batch_set.size() << endl;
return 0;
}

 
if(argc>=2)
{
ifstream infile(argv[1]);
...
}
else
{
// no parameters
...
}
 
Good to see that the set container worked for you.

To read in the file name as a command line argument, replace

Code:
ifstream infile(&quot;input.txt&quot;);

with

Code:
ifstream infile(argv[1]);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top