Click here to Skip to main content
15,912,504 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
i am beginner in c++
i have defined a 2d char array,now how can i input data in it?

int i;
char str[100][100];
for (i=0;i<100;i++)
cin.get(str[i],100);

i want to save string in each row in array
this is my code but it doesn't work!
Posted
Updated 20-Apr-11 7:53am
v2

1 solution

Not sure what your goal is, but perhaps something like this:

C++
int i;
char str[100][100];
for (i=0;i<100;i++)
{
  for(int j=0; j<100; j++)
  {
    cin >> str[i][j];
  }
}


Note, that's just untested pseudocode. But note how I've used 2 indices there.

[Update]
--------

His alternate thread where he described it with more details (the key point about strings vs chars) has been answered here:

list of strings in an 2d array[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900