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;

		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

					case 'd': // deposit   

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


					case 'w': // withdrawal    

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

6 Years
Discussion Span
Last Post by SgtMe

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;
	int j = 0;
	while (j < 20){cout<<array_data[j]<<endl; j++;}

int Main(){

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.