How to get null terminated pointer of a string in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

int main()
{
	string s("c++ programming");

	const char *p = s.c_str();

	cout << p << endl;

	return 0;
}

/*
run:

c++ programming

*/

 



answered May 8, 2018 by avibootz

Related questions

1 answer 150 views
150 views asked May 13, 2021 by avibootz
1 answer 133 views
1 answer 125 views
125 views asked May 13, 2021 by avibootz
2 answers 253 views
2 answers 173 views
173 views asked May 5, 2017 by avibootz
...