yow_sky Posted May 12, 2014 Share Posted May 12, 2014 c++ İYİ BİLEN ARKADASLARA.. BİR STRİNG DİZİSİ İÇERSİNDE İSİM KAYITLI ATIYORUM mehmet_ali_alabora burada bulanan ''_'' göre isim soy isim olarak nasıl ayırırız tek isimli oldumu sıkıntı yok ama iki tane isim oldumu sıkıntı oluyor lütfen yardımcı olun bana ? Kullandığım program visiual studio Quote Link to comment Share on other sites More sharing options...
MostWanted Posted May 12, 2014 Share Posted May 12, 2014 Herhangi bi kod parçası vermediğin için aşağıdaki örneği tamamen farazi yazdım, kendine göre düzenlersin; unsigned found = str.find_last_of('_'); //str şu anki stringin cout << " isim kısmı: " << str.substr(0,found) << '\n'; cout << " soy isim : " << str.substr(found+1) << '\n'; iki isimlilerde "_" silmen gerekebilir onun içinde replace metodunu kullanabilirsin. Quote Link to comment Share on other sites More sharing options...
yow_sky Posted May 13, 2014 Author Share Posted May 13, 2014 Mantık şu kardeşim eger okutmaya en sondan itibaren başlarsak gördüğümüz ilk " _ " sonrası isme denk gelir ikili isimler olsun tekli isimler olsun farketmez buna uygun bir kod üzerinde uğraşıyorum ama beceremedim bir türlü Quote Link to comment Share on other sites More sharing options...
MostWanted Posted May 13, 2014 Share Posted May 13, 2014 (edited) Verdiğim kod zaten bu işe yarıyor. "str" değişkeninin içeriğinde "alt tireli isim" olduğunu varsaydım.Kodunu ona göre düzenlemen gerekiyor. Edit: find_last_of metodu verdiğin parametreden bulunan son char ın poziyonunu verir.Parametre olarak "_" verdik, metod bize string içinde o değerin son bulunduğu yeri verecek.Buda soyisimden önceki "_" oluyor.Bulunan poziyona göre substr ile ayırma işlemi yapıyorsun.Acaba yazdığım şeyi hiç denedin mi? Edit2: #include <string> #include <iostream> using namespace std; int main(){ string tnctr = "Mehmet_Ali_Yılmaz"; unsigned found = tnctr.find_last_of('_'); //str şu anki stringin cout << "isim kısmı: " << tnctr.substr(0,found) << endl; cout << "soy isim : " << tnctr.substr(found+1) << endl; return 0; } Çalışan örnek de ekledim. Edited May 13, 2014 by MostWanted Quote Link to comment Share on other sites More sharing options...
yow_sky Posted May 13, 2014 Author Share Posted May 13, 2014 Attığın bu kodla projem tamamlanmış oldu kardeşim Allah ne muradın varsa versin.. :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.