ok guys one quick question for you. If im reading a file say formated like so..

123 d52.55 w52.66 d55.55 d66.66
456 w55.55 d55.55 d66.6


and i want to read the first variable so 123 and match it up with another file. how do i go about reading the rest of the line without running into the next line. I want to devide up each part ie. d is for deposit and then amount and for the account number 123. I have a program that runs but it assigns all withdrawl and deposits for 123 so it skips over 456 and dosnt read it.

int fillArrayT( PersonAcct customerArray[7], ifstream& inFileT)
{

	char tranType = 'w';
	float amount;
	int accountno;
	int i=0;
	customerArray[i].withdrawl = 0;
	customerArray[i].deposit = 0;

	while(!inFileT.eof())
	{
		cout << " outer while loop" << endl; // testing purpose
			inFileT >> accountno;
			for ( i = 0 ; i< 6 ; i++)
			if ( accountno == customerArray[i].acct_num )
			{ 
				cout << " TESTING" << endl; // testing purpose

				while(inFileT >> tranType >> amount)  
				{
					cout << " money" << endl; // testing purpose
					switch(tranType)    

					{       
					case 'd': // deposit   

						customerArray[i].deposit = customerArray[i].deposit + amount;
						customerArray[i].timesD = 0;
						customerArray[i].timesD +=1;
						cout << "value d" << amount ; // testing purpose

						break;    




					case 'w': // withdrawal    


						customerArray[i].withdrawl =	customerArray[i].withdrawl - amount;
						customerArray[i].timesW = 0;
						customerArray[i].timesW +=1;
						cout << " value w"<< amount; // tesing purpose
						break;    
					}   
						

				}
				
			
		}
	}

You would want to read the line into an array, and split it at the spaces, so you have little blocks of data. Obviously the first array value (position 0) will be "123", so you can just leave that one, but the next bit would be "d52.55". You would want to read the first character of that string to determine a deposit or withdrawal, and put the value of "52.55" into a variable of type float.

Here's part of a program I made a while ago (The test string there was from someone else's project that I helped with a while back). It uses tokens with stringstream to split strings into arrays. Have a look through and see if you can adapt it to be put in your code.

#include <string>
#include <sstream>
#include <iostream>
using namespace std;
string SplitVerts(string data)
{
	string in_data=data;
	string array_data[20];
	stringstream split(in_data);
	string token = ",";
	int i = 0;
	while (split>>token){
		array_data[i] = token;
		i++;
	}
	int j = 0;
	while (j < 20){cout<<array_data[j]<<endl; j++;}
}

int Main(){
           cout<<"105:1:CME,20100601,07:34:22.796,GRC,GE,201009,FUT,XGGRC,0G4LHZ013,14ijpol1vsu7l7,Fill,0000D9DB,B,00000,99.155,2,99.155,20100601,07:27:34"<<endl;                                                                                                                              
}

Other than that, do a few google searches and see what you can turn out.
Hope this helps :) (If so, please upvote :P )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.