File Processing

Learning my first programming language and am having trouble.
Firstly, the myfile.dat looks like

1Kmp6z|Johnny Five|123 Mains St|9.52|

Part number 1-6
Customer name 7-26
Address 27-42
balance 43-60

Visual studio breaks every time i run the program and the output is over my head.

basically, how can i clean this code up to run the .dat file (without displaying the | ) so...

1Kmp6z Johnny Five 123 Mains St 9.52
is how i would like it to be displayed

Secondly, if i wanted to save the information would i save it to a .txt or
is there a way i can save it to a .xml

output.open("c:\\outputfile.txt")
or
output.open("c:\\outputfile.xml")

Your time and help is much appreciated, i am a newbie, constructive criticism is appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	ifstream myfile;
	string inputLine, partnumber, name, address, balance,junk,mystring;
	int nextPipePosition;

	myfile.open("c:\\myfile.dat");
	

	getline ( myfile, inputLine);
	partnumber = inputLine.substr(0,6 );
	name = inputLine.substr(6, 20);
	address = inputLine.substr(26, 15);
	balance = inputLine.substr(42, 18);


	//debug input from file
	cout << "|" << partnumber << "|" << endl;
	cout << "|" << name << "|" << endl;
	cout << "|" << address << "|" << endl;
	cout << "|" << balance << "|" << endl;
	//
	nextPipePosition = mystring.find("|");
	partnumber = mystring.substr(0,nextPipePosition + 0);
	mystring = mystring.substr(nextPipePosition +0, mystring.length() -        nextPipePosition +0);
	
	nextPipePosition = mystring.find("|");
	name = mystring.substr(0,nextPipePosition + 0);
	mystring = mystring.substr(nextPipePosition +0, mystring.length() -   nextPipePosition +0);
	
	nextPipePosition = mystring.find("|");
	address = mystring.substr(0,nextPipePosition + 0);
	mystring = mystring.substr(nextPipePosition +0, mystring.length() - nextPipePosition +0);

	
	balance = mystring;

	//close files
	myfile.close();
	

	//freeze screen
	cout << endl << endl;
	cout << " Press any key followed by enter ";
	cin >> junk;


	return 0;
}
To save it on XML you will need to import a library file. Create the program on C# better format as it provides you the tools for saving XML file.
Topic archived. No new replies allowed.