Hi frnds
I am having some kind of problem in strings.. I have to write a String program whose output is like this

Let the string is :-

Enter string : "Computer Programming"
C
Co
Com
Comp
Compu
Comput
Compute
Computer
Computer P
Computer Pr
Computer Pro
Computer Prog
Computer Progr
Computer Progra
Computer Program
Computer Programm
Computer Programmi
Computer Programmin
Computer Programming

I Have tried much to make this program but not successful..Can anyone help me. Thank you :)

Print out the values of the array containing the string using a loop
the number of letters that would be shown would depend on the current value of the counter

try this

#include <iostream>
using namespace std;


int main(int argc, char **argv)
{
	string foo, bar;
	cout <<"Enter a word :\n";
	getline(cin,foo);
	for(unsigned int ista=0;ista <foo.length();++ista){
		bar += foo[ista];
		cout <<bar<<endl;
		}
	return 0;
}

Thanks I got 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.