Find largest substring in alphabetical order in a given string
Here are a few details :

Variable declaration

It is usually a good idea to move your variable declaration in the smallest possible scope as close as possible to where they are getting used.

This for instance shows that sub is never used.

Also, you can take this chance to change your while loop into a for loop and declare i in it.

Warnings

It is a good thing to activate all warnings. For instance, I get :


  warning: comparison between signed and unsigned integer expressions
  [-Wsign-compare]


Simplifying things

Instead of messing with prev, you can detect if i has been increased already by considering the value of check.

Cast

I do not think these casts are useful.

Length

It could be a good idea to store the length of the string in a variable not to retrieve it at every iteration.

Using namespace

using namespace is sometimes frowned upon.

At this stage the code looks like :

#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    std::string s = "vjvdfkjckvjkjrdsfjsdkjfliureyqnbcxvfjhdeiutogfvjdsvkdfcdcoivjriofdjsrs";
//    std::cin &gt;&gt; s;
    int count = 0, pos = 0; // keeping count of number of alphabetical ordered substring characters

    for (size_t i = 1, len = s.size() ; i &lt; len ; )
    {
        int check = 1;
        while (s[i] &gt;= s[i - 1])
        {
            ++check;
            ++i;
        }
        if (check &gt; count)
        {
            count = check;
            pos = i - check;
        }

        if (check == 1)
            ++i;
    }
    std::cout &lt;&lt; "Longest substring in alphabetical order is :" &lt;&lt; s.substr(pos, count) &lt;&lt; std::endl;
}


Algorithmic trick

A trick could be to say that if you have a current result of length n, you don't care about any substring of length m &lt; n. Thus, you can check backward from position i + n : as long as it is in descending order, you continue, otherwise, it gives you a starting position to start again.

I am not sure if this is really clear. I'll tr to improve asap.