954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

strings in C++

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 :)

omer620
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

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;
}
richieking
Master Poster
764 posts since Jun 2009
Reputation Points: 61
Solved Threads: 152
 

Thanks I got it !

omer620
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: