need help urgent!!

Write your question here.

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
  #include <iostream>
#include <cmath>
#include<iomanip>
#include<string>
using namespace std;

void main (void)
{
	const int Max=1000;
	int i=0,n,j=0,k=0,t;
	int count[100];
	string Nachname,text,Vorname,Matrikulnr,info[Max];
	string Nchnam[Max],Vrnam[Max],Matrikul[Max];
	cout<<"geben Sie der Anzahl der Informationen ein\t";
	cin>>n;
	if(n<=1 || n>=Max)
	{
	   cout<<"Eingabefelher"<<endl;
	}
	else
	{
		cout<<"geben sie die informationen ein:\n";
	    do
	    {
		   getline(cin,info[i]);
		   i++;
		}while(i<=n);
	    for(i=1;i<=n;i++)
	    {
		   cout<<"info"<<" "<<i<<"="<<info[i].size()<<"\n";
	    }
      }
}	


using of getline() in these case is false.i donĀ“t understand why??? the first value of info[] is always 0 !! why please a i need response
In C++ main returns an int.

Change void main to int main

and add return 0; before the closing }

After that I compiled and ran the code and it did what you wrote it to do. Are you having another issue?
Lets say that the input was
42<Return>
foo<Return>
Where `<Return>' means that you've pressed the Return key in the keyboard.

So the input buffer is "42\nfoo\n" when you cin>>n you read the number
"\nfoo\n" remains.

What `getline()' does is simply to read until a line break is found. That's the first character, so the result is empty.
The buffer contains "foo\n"


To avoid this first empty line, simply discard the line break after reading the number
1
2
cin>>n;
cin.ignore();

Topic archived. No new replies allowed.