data file conversion

Generate a data file to test all the features of the following program. Then write a program that reads a file that only contains integers, but some of the integers have embedded commas, as in 145,020. The program should copy the information to a new file, removing any commas from the information. Do not change the number of values per line in the file.\

Here's what I have so far. It compiles but doesnt give me anything useful. Im not sure where to go from where i am.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

int main()
{
{
//Declare and initialize objects
char integers;
string filename, outfile;
ofstream list;

// Prompt user for name of output file
cout << "Enter the name of the output file\n";
cin >> filename;

// Open output file
list.open(filename.c_str());

//Print out list of integers
cout << "List of Integers:" << endl;
cout << "512 56 234,643 6,363 857" << endl;
cin >> integers;

// Write report information to a file
list << integers << endl;

}
// Created the data file now have to create conversion of data file
{
//Declare and initialize objects
char integers;
string filename, outfile;
bool list_state(true);
ifstream list;
ofstream listtxt;

//Prompt user for input file
cout << "Enter the name of the input file\n";
cin >> filename;

//Prompt user for output file
cout << "Enter the name of the output file\n";
cin >> outfile;

//Open input file
list.open(filename.c_str());

if(list.fail())
{
cerr << "Error opening input file\n";
exit(1);
}

//Open output file and read first character from list file
listtxt.open(outfile.c_str());
list.get(integers);

while(!list.eof())
{
if(list_state)
{
if(integers == ',')
list_state=false;
else
cout << integers;
}

}

list.close();
listtxt.close();

}
}


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
FYI, you don't need _tmain() in there.

You are on the right track. However, you need to keep get()ing integers from the file until you reach the end, since right now you are just get()ing once, then looping without reading any input.
Topic archived. No new replies allowed.