Click here to Skip to main content
12,450,101 members (49,210 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C
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 20-Apr-11 7:35am
Updated 20-Apr-11 7:53am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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[^]
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 20 Apr 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100