c_str() ফাংশন একটি NULL-টার্মিনেটেড ক্যারেক্টার অ্যারেতে পয়েন্টার রিটার্ন করে। স্ট্রিংয়ের ইন্টারনাল বাফারের এক্সেস দেয়।
সিনট্যাক্স
const Char* c_str() const
বিশেষত্ব
- কোনো প্যারামিটার নেয় না।
const char*রিটার্ন করে।- রিটার্ন করা পয়েন্টার স্ট্রিং মডিফাই হলে অবৈধ হয়ে যেতে পারে।
C++ কোড উদাহরণ
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
string s = "I Love Tutorials Point";
int flag = 0;
cout << "Checking if the string " << s << " contains P " << endl;
for(int i = 0; i < s.size(); i++) {
if(s.c_str()[i] == 'P') {
cout << "The string contains character";
flag = 1;
}
}
if(flag == 0)
cout << "The string does not contains character";
return 0;
}
আউটপুট
Checking if the string I Love Tutorials Point contains P The string contains character