0

下面的代码使用 VS 成功编译,但 gcc 给出了 SIGSEGV,标记为 SIGSEGV_E

#include <iostream>
#include <string>
#include <algorithm>
using std::cout;



std::string encode(const std::string& decoded)
{
    std::string encoded_url(decoded);//SIGSEGV_E this line causes gcc to signal SIGSEGV
    typedef typename std::string::iterator iterator;
    for (iterator i = encoded_url.begin();(i = std::find(i,encoded_url.end(),'%')) != encoded_url.end();++i)        {
        cout << *i << *(i + 1) << *(i + 2) << '\n';
    }
    return encoded_url;
}
int main()
{
    std::string decoded_url("http%3A%2F%2Fo-o---preferred---sn-xn5ucu-q0ce---v20---lscache7.c.youtube.com%2Fvideoplayback%3Fupn%3DQfNLYnp9JHM%26sparams%3Dcp%252Cgcr%252Cid%252Cip%252Cipbits%252Citag%252Cratebypass%252Csource%252Cupn%252Cexpire%26fexp%3D907724%252C923009%252C914070%252C916626%252C922401%252C920704%252C912806%252C927201%252C925703%252C925706%252C928001%252C922403%252C913546%252C913556%252C920201%252C911116%252C901451%26ms%3Dau%26expire%3D1354491207%26itag%3D43%26ipbits%3D8%26gcr%3Die%26sver%3D3%26ratebypass%3Dyes%26mt%3D1354467611%26ip%3D89.204.226.98%26mv%3Dm%26source%3Dyoutube%26key%3Dyt1%26cp%3DU0hUSVRUT19FUUNONF9MTlNDOm05Ql9HWWNIejNM%26id%3Dcaf9021d49b11ad9%26newshard%3Dyes&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22&fallback_host=tc.v1.cache5.c.youtube.com&sig=63E945F5FCC5744AFDA6A473D2B7D3A464DC56AE.31AF09E39FFF100E5A5066418689DA3DD4D78C37&quality=medium");
    cout << encode(decoded_url);
    return 0;
}  

任何想法为什么,以及如何克服这个愚蠢的问题?

4

0 回答 0