Fill grid with the users input
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:
- User enters 1234123412341234
- 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++
add a comment |
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:
- User enters 1234123412341234
- 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++
add a comment |
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:
- User enters 1234123412341234
- 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++
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:
- User enters 1234123412341234
- 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++
c++
edited Nov 12 '18 at 4:26
Jake Blazer
asked Nov 12 '18 at 1:35
Jake BlazerJake Blazer
325
325
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Nov 12 '18 at 1:42
user10605163user10605163
2,848624
2,848624
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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