How to Space Arrays into even columns (C++)












-2















For a project I am doing for school, I need to read 2 files, one with month values, and one with visitor data. Reading the files, putting them into arrays is easy, the hard part is spacing. Spacing the arrays is mainly a problem as I have no idea how to space values evenly when the strings, in this case, months of the year, are uneven. With months of the same length, such as June and July, the spacing stays fairly even and neat, the left justifying working, but with uneven month names, the columns begin to swerve and look ugly. Current state of code is shown below.



while (r < 12 && c < 5 && count < 13) { //while loop until the end of each is closed
cout << setw(5) << visitor_data[r][c] << " " << setw(5) << left; //data, space out
c++; //next column
if (c % 5 == 0) { //ends line for each complete row of data
r++; //next row
cout << endl << setw(5); //ends line
cout << months_do[count] << " " << setw(3) << right;
c = 0; //column zero
count++;
}

}









share|improve this question

























  • What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

    – 3Dave
    Nov 25 '18 at 22:47













  • You have 13 months?

    – Killzone Kid
    Nov 25 '18 at 23:05











  • @KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

    – Alex Eley
    Nov 25 '18 at 23:41
















-2















For a project I am doing for school, I need to read 2 files, one with month values, and one with visitor data. Reading the files, putting them into arrays is easy, the hard part is spacing. Spacing the arrays is mainly a problem as I have no idea how to space values evenly when the strings, in this case, months of the year, are uneven. With months of the same length, such as June and July, the spacing stays fairly even and neat, the left justifying working, but with uneven month names, the columns begin to swerve and look ugly. Current state of code is shown below.



while (r < 12 && c < 5 && count < 13) { //while loop until the end of each is closed
cout << setw(5) << visitor_data[r][c] << " " << setw(5) << left; //data, space out
c++; //next column
if (c % 5 == 0) { //ends line for each complete row of data
r++; //next row
cout << endl << setw(5); //ends line
cout << months_do[count] << " " << setw(3) << right;
c = 0; //column zero
count++;
}

}









share|improve this question

























  • What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

    – 3Dave
    Nov 25 '18 at 22:47













  • You have 13 months?

    – Killzone Kid
    Nov 25 '18 at 23:05











  • @KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

    – Alex Eley
    Nov 25 '18 at 23:41














-2












-2








-2








For a project I am doing for school, I need to read 2 files, one with month values, and one with visitor data. Reading the files, putting them into arrays is easy, the hard part is spacing. Spacing the arrays is mainly a problem as I have no idea how to space values evenly when the strings, in this case, months of the year, are uneven. With months of the same length, such as June and July, the spacing stays fairly even and neat, the left justifying working, but with uneven month names, the columns begin to swerve and look ugly. Current state of code is shown below.



while (r < 12 && c < 5 && count < 13) { //while loop until the end of each is closed
cout << setw(5) << visitor_data[r][c] << " " << setw(5) << left; //data, space out
c++; //next column
if (c % 5 == 0) { //ends line for each complete row of data
r++; //next row
cout << endl << setw(5); //ends line
cout << months_do[count] << " " << setw(3) << right;
c = 0; //column zero
count++;
}

}









share|improve this question
















For a project I am doing for school, I need to read 2 files, one with month values, and one with visitor data. Reading the files, putting them into arrays is easy, the hard part is spacing. Spacing the arrays is mainly a problem as I have no idea how to space values evenly when the strings, in this case, months of the year, are uneven. With months of the same length, such as June and July, the spacing stays fairly even and neat, the left justifying working, but with uneven month names, the columns begin to swerve and look ugly. Current state of code is shown below.



while (r < 12 && c < 5 && count < 13) { //while loop until the end of each is closed
cout << setw(5) << visitor_data[r][c] << " " << setw(5) << left; //data, space out
c++; //next column
if (c % 5 == 0) { //ends line for each complete row of data
r++; //next row
cout << endl << setw(5); //ends line
cout << months_do[count] << " " << setw(3) << right;
c = 0; //column zero
count++;
}

}






c++ arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 22:31









drescherjm

6,48523452




6,48523452










asked Nov 25 '18 at 22:29









Alex EleyAlex Eley

11




11













  • What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

    – 3Dave
    Nov 25 '18 at 22:47













  • You have 13 months?

    – Killzone Kid
    Nov 25 '18 at 23:05











  • @KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

    – Alex Eley
    Nov 25 '18 at 23:41



















  • What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

    – 3Dave
    Nov 25 '18 at 22:47













  • You have 13 months?

    – Killzone Kid
    Nov 25 '18 at 23:05











  • @KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

    – Alex Eley
    Nov 25 '18 at 23:41

















What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

– 3Dave
Nov 25 '18 at 22:47







What exactly are left and right? You could also just cout << "tt" between values. Lame, but it usually works.

– 3Dave
Nov 25 '18 at 22:47















You have 13 months?

– Killzone Kid
Nov 25 '18 at 23:05





You have 13 months?

– Killzone Kid
Nov 25 '18 at 23:05













@KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

– Alex Eley
Nov 25 '18 at 23:41





@KillzoneKid For all intents and purposes, this still works for the function. Probably why I'm getting an fstream window prompt though.

– Alex Eley
Nov 25 '18 at 23:41












1 Answer
1






active

oldest

votes


















0














You need to make sure your set widths equal or exceed the maximum number of characters that will be printed. Your width before printing months is set at 5, but if you have the month 'december' spelled out entirely it will exceed the setw and could be causing your uneven columns. Hope this helps!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472663%2fhow-to-space-arrays-into-even-columns-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to make sure your set widths equal or exceed the maximum number of characters that will be printed. Your width before printing months is set at 5, but if you have the month 'december' spelled out entirely it will exceed the setw and could be causing your uneven columns. Hope this helps!






    share|improve this answer




























      0














      You need to make sure your set widths equal or exceed the maximum number of characters that will be printed. Your width before printing months is set at 5, but if you have the month 'december' spelled out entirely it will exceed the setw and could be causing your uneven columns. Hope this helps!






      share|improve this answer


























        0












        0








        0







        You need to make sure your set widths equal or exceed the maximum number of characters that will be printed. Your width before printing months is set at 5, but if you have the month 'december' spelled out entirely it will exceed the setw and could be causing your uneven columns. Hope this helps!






        share|improve this answer













        You need to make sure your set widths equal or exceed the maximum number of characters that will be printed. Your width before printing months is set at 5, but if you have the month 'december' spelled out entirely it will exceed the setw and could be causing your uneven columns. Hope this helps!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 21:47









        kR104743kR104743

        62




        62
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472663%2fhow-to-space-arrays-into-even-columns-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'