I am a newbie in c++ coding and I found an unusual error in my code. I have no idea where did I go wrong, can anyone point out my mistake ? I am making a code that will create a new line after founding the limit characters inputted by the user. Edit : after declaring j value to zero, I try to cout << b and its equal zero. I am confused now because I have already used getline command to get the number of chars.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string input;
string output;
int sum=0;
int counter;
string line;
int w;
int main()
{
    ifstream inFile;
    cout << "Input Text File Name :";
    cin >> input;
    if(inFile.fail())
    {
        cerr << "Error Opening Text" << endl;
        return 1;
    }
    else
        cout << "Output Text File Name :";
    cin >> output;
    ofstream outFile;
    cout << "Texth Width to Format ( >10 ):";
    cin >> w;
    inFile.is_open();
    outFile.open(output);
    while(!inFile.eof())
    {
        getline(inFile,line);
        int b = line.length();
        int i, n, j;
        i = 0;
        n = 1;
        j=0;
        while(j != b)
        {
            for (i; i<n*(w-1); i++)
            {
                outFile << line.at(i);
            }
            i= i;
            outFile << endl;
            n++;
            j += n*(w-1);
        }
        sum=b+sum;
    }
    outFile.close();
    inFile.close();
    cout <<"Number of characters in this Text File is :" << sum;
    return 0;
}
thank you for your help !
