Hi. Another newbie here looking for some insight.

I have a menu drivin program with 5 functions. got first 3 down and the 4th wants me to read a plain text fil and output the length of the longest line.

I know as far as getline(infile,str). where str is just the generic variable for my string. but how to i count how many characters are in said string.

I have this so far. i know its far off, but hey i gotta start somewhere.

//priming read
			getline(infile,str);
			
			//letter count loop
			while (!infile.eof()) 
			{
				if ()
					count++;
				
				getline(infile,str); //reset

				while (letter == '\n' ) //when letter is at a new line do this
				{
					if (totalcount <= count) 
					{
						totalcount = count;
					}
				}

havent really gotten much into string. so im not sure if str.size() if off limits.

str.size() is fine, and recommended

you create an integer (or size_t) 'max' (or whatever) and check if the current line's size is > than max and if it is store the new size as max:

size_t max;

if( max < str.size( ) )
   max = str.size( );

right as i received the notification for this i figured it out with .size()


thanks for the response though. i appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.