We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,845 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

3
Contributors
3
Replies
5 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
omer620
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

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
789 posts since Jun 2009
Reputation Points: 58
Solved Threads: 156
Skill Endorsements: 0

Thanks I got it !

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

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0607 seconds using 2.65MB