Fill grid with the users input










1














Okay, so I am a bit stuck. I am trying to ask the user to enter 16 characters and output their input into a grid. However, I keep running into an error:




Error: cannot convert 'std::__cxx11::string aka std::__cxx11::basic_string<char>' to 'char' in assignment.




I don't understand what the error is and I did my best to try and figure out the issue but not working.



For example:



  1. User enters 1234123412341234

  2. It should output:

1 2 3 4



1 2 3 4



1 2 3 4



1 2 3 4



Here is the code:



#include <iostream>
#include <stdlib.h>

using namespace std;

void fillLgArray(char grid[LG_GRID], int direction);

void outputLgArray(char grid[LG_GRID]);


int main()

char myGrid1[LG_GRID][LG_GRID];
doCommand (myGrid1);

return 0;



void fillLgArray(char grid[LG_GRID], int direction)

string userInput;

cout << "Please enter 16 characters!n";
cin >> userInput;

if(userInput.length() > 16)

userInput = userInput.substr(0, 16);


cout << "You entered " << userInput << endl;

if (direction = 1)
for (int row = 0; row < LG_GRID; row++)
for (int col = 0; row < LG_GRID; row++)
grid [row][col] = userInput;





void outputLgArray(char grid[LG_GRID])

for (int row=0;row <LG_GRID;row++)
for(int col=0;col <LG_GRID;col++)
cout << grid[row][col]<<" ";

cout << endl;











share|improve this question




























    1














    Okay, so I am a bit stuck. I am trying to ask the user to enter 16 characters and output their input into a grid. However, I keep running into an error:




    Error: cannot convert 'std::__cxx11::string aka std::__cxx11::basic_string<char>' to 'char' in assignment.




    I don't understand what the error is and I did my best to try and figure out the issue but not working.



    For example:



    1. User enters 1234123412341234

    2. It should output:

    1 2 3 4



    1 2 3 4



    1 2 3 4



    1 2 3 4



    Here is the code:



    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    void fillLgArray(char grid[LG_GRID], int direction);

    void outputLgArray(char grid[LG_GRID]);


    int main()

    char myGrid1[LG_GRID][LG_GRID];
    doCommand (myGrid1);

    return 0;



    void fillLgArray(char grid[LG_GRID], int direction)

    string userInput;

    cout << "Please enter 16 characters!n";
    cin >> userInput;

    if(userInput.length() > 16)

    userInput = userInput.substr(0, 16);


    cout << "You entered " << userInput << endl;

    if (direction = 1)
    for (int row = 0; row < LG_GRID; row++)
    for (int col = 0; row < LG_GRID; row++)
    grid [row][col] = userInput;





    void outputLgArray(char grid[LG_GRID])

    for (int row=0;row <LG_GRID;row++)
    for(int col=0;col <LG_GRID;col++)
    cout << grid[row][col]<<" ";

    cout << endl;











    share|improve this question


























      1












      1








      1







      Okay, so I am a bit stuck. I am trying to ask the user to enter 16 characters and output their input into a grid. However, I keep running into an error:




      Error: cannot convert 'std::__cxx11::string aka std::__cxx11::basic_string<char>' to 'char' in assignment.




      I don't understand what the error is and I did my best to try and figure out the issue but not working.



      For example:



      1. User enters 1234123412341234

      2. It should output:

      1 2 3 4



      1 2 3 4



      1 2 3 4



      1 2 3 4



      Here is the code:



      #include <iostream>
      #include <stdlib.h>

      using namespace std;

      void fillLgArray(char grid[LG_GRID], int direction);

      void outputLgArray(char grid[LG_GRID]);


      int main()

      char myGrid1[LG_GRID][LG_GRID];
      doCommand (myGrid1);

      return 0;



      void fillLgArray(char grid[LG_GRID], int direction)

      string userInput;

      cout << "Please enter 16 characters!n";
      cin >> userInput;

      if(userInput.length() > 16)

      userInput = userInput.substr(0, 16);


      cout << "You entered " << userInput << endl;

      if (direction = 1)
      for (int row = 0; row < LG_GRID; row++)
      for (int col = 0; row < LG_GRID; row++)
      grid [row][col] = userInput;





      void outputLgArray(char grid[LG_GRID])

      for (int row=0;row <LG_GRID;row++)
      for(int col=0;col <LG_GRID;col++)
      cout << grid[row][col]<<" ";

      cout << endl;











      share|improve this question















      Okay, so I am a bit stuck. I am trying to ask the user to enter 16 characters and output their input into a grid. However, I keep running into an error:




      Error: cannot convert 'std::__cxx11::string aka std::__cxx11::basic_string<char>' to 'char' in assignment.




      I don't understand what the error is and I did my best to try and figure out the issue but not working.



      For example:



      1. User enters 1234123412341234

      2. It should output:

      1 2 3 4



      1 2 3 4



      1 2 3 4



      1 2 3 4



      Here is the code:



      #include <iostream>
      #include <stdlib.h>

      using namespace std;

      void fillLgArray(char grid[LG_GRID], int direction);

      void outputLgArray(char grid[LG_GRID]);


      int main()

      char myGrid1[LG_GRID][LG_GRID];
      doCommand (myGrid1);

      return 0;



      void fillLgArray(char grid[LG_GRID], int direction)

      string userInput;

      cout << "Please enter 16 characters!n";
      cin >> userInput;

      if(userInput.length() > 16)

      userInput = userInput.substr(0, 16);


      cout << "You entered " << userInput << endl;

      if (direction = 1)
      for (int row = 0; row < LG_GRID; row++)
      for (int col = 0; row < LG_GRID; row++)
      grid [row][col] = userInput;





      void outputLgArray(char grid[LG_GRID])

      for (int row=0;row <LG_GRID;row++)
      for(int col=0;col <LG_GRID;col++)
      cout << grid[row][col]<<" ";

      cout << endl;








      c++






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 4:26







      Jake Blazer

















      asked Nov 12 '18 at 1:35









      Jake BlazerJake Blazer

      325




      325






















          1 Answer
          1






          active

          oldest

          votes


















          1














          grid [row][col] = userInput;


          You are trying to assign the whole userInput (which has type std::string aka std::__cxx11::basic_string and is multiple characters long) to a single character grid[row][col] (which is of type char). Specify which character of the string you want to save in the grid[row][col]:



          grid [row][col] = userInput[...];


          Replace ... by the character index you want to choose.



          Not related to question:



          for (int col = 0; row < LG_GRID; row++){


          row should be col in both cases, otherwise you are not ever actually changing col.






          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%2f53254979%2ffill-grid-with-the-users-input%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









            1














            grid [row][col] = userInput;


            You are trying to assign the whole userInput (which has type std::string aka std::__cxx11::basic_string and is multiple characters long) to a single character grid[row][col] (which is of type char). Specify which character of the string you want to save in the grid[row][col]:



            grid [row][col] = userInput[...];


            Replace ... by the character index you want to choose.



            Not related to question:



            for (int col = 0; row < LG_GRID; row++){


            row should be col in both cases, otherwise you are not ever actually changing col.






            share|improve this answer

























              1














              grid [row][col] = userInput;


              You are trying to assign the whole userInput (which has type std::string aka std::__cxx11::basic_string and is multiple characters long) to a single character grid[row][col] (which is of type char). Specify which character of the string you want to save in the grid[row][col]:



              grid [row][col] = userInput[...];


              Replace ... by the character index you want to choose.



              Not related to question:



              for (int col = 0; row < LG_GRID; row++){


              row should be col in both cases, otherwise you are not ever actually changing col.






              share|improve this answer























                1












                1








                1






                grid [row][col] = userInput;


                You are trying to assign the whole userInput (which has type std::string aka std::__cxx11::basic_string and is multiple characters long) to a single character grid[row][col] (which is of type char). Specify which character of the string you want to save in the grid[row][col]:



                grid [row][col] = userInput[...];


                Replace ... by the character index you want to choose.



                Not related to question:



                for (int col = 0; row < LG_GRID; row++){


                row should be col in both cases, otherwise you are not ever actually changing col.






                share|improve this answer












                grid [row][col] = userInput;


                You are trying to assign the whole userInput (which has type std::string aka std::__cxx11::basic_string and is multiple characters long) to a single character grid[row][col] (which is of type char). Specify which character of the string you want to save in the grid[row][col]:



                grid [row][col] = userInput[...];


                Replace ... by the character index you want to choose.



                Not related to question:



                for (int col = 0; row < LG_GRID; row++){


                row should be col in both cases, otherwise you are not ever actually changing col.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 '18 at 1:42









                user10605163user10605163

                2,848624




                2,848624



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53254979%2ffill-grid-with-the-users-input%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

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo