Let's say I have a large random string like so...

```
_W:,aLH#J&A4=IY;    ?RVUc?W+</59JG4WSGW6G6$QEHQ:>,*b60$BYR=D=-^8-4(0    "??YaI0Y    SD9 FJ;MZ,V+'S]0:9L%;#a23cO%bMY[O6^S;ULRV2XA    8&  6_5W21E+Y$RYY$K"Q.0J+:cJC301M3H![7
L%K
Q5(4I9/9DAFR,-8<BJ=4H>9M,OX!.A4aQ:
BK<a"1ID.=U-US`R_])>GG)UL\!G?U$RRG_
HcW 3;<U5`X.?:6K@H*ZD3[M!ZU#KJXbE<Y*VV#ZYU#=]?Q
5:a^]#T

XRT.V]>57#W"U1=K$X]&JIY)::AE :K'7!_DV1B>SJ9D_`]>aC"N'US$;CaHK<N#-
"cJ,%RT)!J0DLFUb[[FOCQX(/.E3#
U
L$("+$) ;TDZ
;T#XS-'6U4`UKZ0a85D&+a]I.C/-7LDM_#/aS9OYA!#^G1II*XKL`;c
ES62Wa^=BQHK6E&A .X+4FDZ:   3UOaJ
#1<BY:;@D:`^`8E\-[9&7PXPH

... a lot more

```

And I want to do an operation over the entire string, like inserting newlines after semi-colons.

```cpp
#include <iostream>
#include <cmath>
#include <algorithm>

int main()
{
    std::string buffer = "";
    std::string line = "";
    while (std::getline(std::cin, line))
        buffer += line + std::string("\n");

    auto it = std::find(buffer.begin(), buffer.end(), ';');
    while (it != buffer.end())
    {
        buffer.insert(it, '\n');
        it = std::find(it+1, buffer.end(), ';');
    }
    std::cout << buffer << std::endl;
    return 0;
}

```

This obviously takes too long. What should I do? Would it be better if I chunked them into smaller strings? If not, how can I make this faster?

**EDIT**

I'm an idiot. I had an infinite loop at this line here

```
- it = std::find(buffer.begin(), buffer.end(), ';');
+ it = std::find(it+1, buffer.end(), ';');

```

Although I still give credit to the person who provided a nice answer.