Please excuse me if this has already been covered before.

I'm a C++ beginner, and in of the problems I have to do, the input has to be like this:
1) A number n is entered.
2) n number of strings are entered.

I tried using a 2D character array to do the above, but it doesn't work. I have to hit the return key after each letter of each string. Could anyone point me to a method where I can *declare* n number of strings, where the user inputs number n?

Thanks for your time. :)

Post the code you tried.You could probably use the same character array for all n number of strings because you didn't say there was a requirement to save all those strings.

This is the code I tried:

#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	char a[n][15];      //size of each string should be 14
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<14; j++)
		cin >> a[i][j];
	}
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<14; j++)
		cout << a[i][j] << endl;
	}
	return 0;
}

I need to save the strings, yes.

line 9: that will not compile with most compilers because that feature is new to c99 standards and most compilers older than that. If you want to use charcter arrays then you will have to allocate them at runtime

int n;
char ** a;
cin >> n;
a = new char*[n];
for (int i=0; i<n; i++)
{
    a[i] = new char[15];
    cin.getline(a[i], 14);
}
Comments
Nice code, I did not know this. =)
This question has already been answered. Start a new discussion instead.