1,105,332 Community Members

strings in C++

Member Avatar
omer620
Newbie Poster
5 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
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

Member Avatar
richieking
Posting Shark
926 posts since Jun 2009
Reputation Points: 40 [?]
Q&As Helped to Solve: 171 [?]
Skill Endorsements: 3 [?]
 
0
 

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;
}
Member Avatar
omer620
Newbie Poster
5 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks I got it !

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: