want to create table

I want to create a table of names.
which type of data type I should use? can somebody give sample code?
Table implies rows and columns.

If it's just of names, the that implies it's just the one column, which implies it's just a list.

So, probably just use a std::vector<std::string>?

Other than that, you'll need to be more specific and provide some code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;

 struct person
    {
        char name[20];


    };

int main()
{
   int i=0,j=0;
   person p1[4][4];
 cout<<"Enter the name of subject "<<'\n';
   for(i=0;i<4;i++)
  {  for(j=0;j<4;j++)
      {

       cin>>p1[i][j].name;

       }

  }
       for(i=0;i<4;i++)
       {
        for(j=0;j<4;j++)

       {
           cout<<p1[i][j].name<<'\t';
       }
       cout<<'\n';
       }

   return 0;
}


I have used this code to make table.

how do I use vectors to make table like this
Your struct person does not add anything substantial to the array of char in it.
std::string is much more safe and convenient than an array of char.

Data does not have to be in a table in order to show it as a table.

Lets do those changes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

int main() {
  using std::cin;
  using std::cout;
  using Person = std::string;

  constexpr int N = 4;
  Person p1[ N*N ];
  cout << "Enter the name of subject\n";

  for ( int i=0; i < N*N; ++i ) {
    cin >> p1[i];
  }

  for ( int row=0; row < N; ++row ) {
    for ( int col=0; col < N; ++col ) {
      cout << p1[ row*N + col ] << '\t';
    }
    cout<<'\n';
  }
   return 0;
}

To use vector, replace line 10 with std::vector<Person> p1( N*N );
and the N*N on line 13 with p1.size()
Topic archived. No new replies allowed.