मैं सी ++ में एक बुनियादी शिफ्ट सिफर लागू करने की कोशिश कर रहा हूं। मैं तब तक आगे नहीं बढ़ सकता जब तक कि मुझे पता न लगे कि सेगमेंटेशन गलती क्या हो रही है। मैंने जीडीबी का उपयोग कर कोड के माध्यम से कदम रखा और समस्या इटेटरेटर से निकलती प्रतीत होती है।इस स्ट्रिंग के माध्यम से पुनरावृत्ति करते समय मुझे सेगमेंटेशन गलती क्यों मिलती है?
1 #include <iostream>
2 #include <string>
3
4 std::string encrypt (std::string plain, int key);
5
6 int main()
7 {
8 std::string plaintext;
9 std::getline(std::cin,plaintext,'\n');
10 encrypt(plaintext,3);
11 }
12
13 std::string encrypt(std::string plain, int key)
14 {
15 std::string::iterator ic;
16 for (ic= plain.begin(); ic != plain.end();++ic)
17 {
18 std::cout <<*ic + key << std::endl;
19 }
20 }
त्रुटि:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b73ef1 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()() from /usr/lib/libstdc++.so.6
लेकिन उसे '~ basic_string' में एसआईजी क्यों मिलता है? – osgx
आह धन्यवाद यह तय किया गया है कि –
मुझे यह भी पता नहीं था कि यह संकलित हो सकता है। जिस तरह से @ कर्नेल, सही जवाब स्वीकार करना न भूलें! – Marlon