Reading input file txt and sorting it out in output file txt

deleted.
Last edited on
Hello winter89,

When it comes to files I like to use this:
1
2
3
4
5
6
7
8
9
10
11
const std::string inFileName{ "" };  // <--- Put File name here.

std::ifstream inFile(inFileName);

if (!inFile)
{
    std::cout << "\n File " << std::quoted(inFileName) << " did not open." << std::endl;  // <--- Requires header file <iomanip>. Or reverse the comments.
    //std::cout << "\n File \"" << inFileName << "\" did not open." << std::endl;

    return 1;
}

If the file did not open the return statement leaves the program until you fix the problem.

The only difference for an output file is I change "in" to "out" and "return 1" to "return 2".

This will eliminate the need to run the rest of "main" with an if/else statement. It may work, but it is bad form.

The while loop is good for reading the file.

I am not sure what this part is or what you are trying to do with it?
1
2
3
4
priceCount = 0;
priceTotal = 0;
priceCount++;
priceTotal += price;


If you have not worked up any code yet, please do so and post it.

Bits and pieces out of context are not helpful until you have a program that can be compiled and tested.

It is always best to provide enough of a program that can be compiled and tested and contain enough do duplicate any error you may have.

Speaking of errors it is also best to post the complete error message that the compiler gives you. Those who read it will understand the message better and can explain what you do not understand.

Andy
Last edited on
Either to much work or got answer and left.

Hello winter89,

It just occurred to me. Work in small steps or parts.

First get the input file and the output file to open.

Next get the first record of the input file and see what you need to do with it.

Work on the input then write it to the output file.

Do just 1 first then add the loop to read the whole file.

Andy
Last edited on
Topic archived. No new replies allowed.