simple question in strings

can anyone Help here ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# include <iostream>
# include <algorithm>
# include <string>
using namespace std;
struct name
{
	string sentence [100] ; // initialized size
} ;
int main ()
{
	name a [100] ;
        int counter = 0 , index [1000] ;


	while (counter < 2)
	{
		getline (cin , a[counter].sentence) ;   // in order to make this line correct I will need to put the size of the sentence.......what size can I put to make the user enters a line
		index [counter] = a[counter].sentence .length () ;  // also here too......what size of sentence  can I put to get the full length of the string
		counter ++ ;
	}

}
Last edited on
getline will fill sentence with whatever the user entered untill he pressed enter.

So your code will work fine without changes
it gave me a syntax error
in the visual studio 2012
I think the change that's needed here is to make "sentence" a string, rather than an array of strings:
string sentence; // no [100]
Last edited on
yes, i see. you use sentence as a string but in your name struct it's an array of strings
Topic archived. No new replies allowed.