stringConcat - // (In Java, this loop takes forever. ..)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// stringConcat.cpp / // Show how C++ strings are mutable, by concatenating // characters to an existing string. Also, show that // C++'s implementation is more efficient than that of java. / // strings are mutable (thinly disguised array of bytes) / // by Mark Weiss / #include <iostream> #include <string> using namespace std; u // Return a string of length n filled with letter A's.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // (In Java, this loop takes forever. ..) string makeLongString( int n ) { string result = &quot;&quot;; s for( int i = 0; i &lt; n; i++ ) result += &quot;A&quot;; r return result; } void stringConcat( ) { string bigString = makeLongString( 250000 ); s cout &lt;&lt; &quot;Length is &quot; &lt;&lt; bigString.length( ) &lt;&lt; endl; c }...
View Full Document

Ask a homework question - tutors are online