Problem std::out_of_range
Ostatnio zmodyfikowano 2015-06-04 19:16
BartC Temat założony przez niniejszego użytkownika |
Problem std::out_of_range » 2015-05-29 21:51:49 Witam. Mam problem z tym co w temacie. Błąd wygląda tak: terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase. Mój kod: #include <iostream> #include <string>
std::string konwertuj( std::string & sTekst ) { std::string sWynik; sWynik.erase( 23, 8 ); return sWynik; } int main() { std::string tekst = "<b>to jest </b> testowy napis :)"; std::cout << konwertuj( tekst ) << std::endl; return 0; }
|
|
notabigthreat |
» 2015-05-29 21:59:52 sWynik jest pusty. Jak chcesz robić kopię, to może po prostu przekaż przez wartość? |
|
Maciek |
» 2015-06-04 19:16:22 Pytanie - który napis chcesz konwertować ? Przypuszczam, że ten który jest w argumencie funkcji, jeśli tak, to zupełnie niepotrzebnie tworzysz lokalny obiekt klasy std::string. Jeśli tak jest, to powinieneś pracować na argumencie funkcji (tak chyba wynika z kodu - bo nie jest to stała). |
|
« 1 » |