How to get the length (size) 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");

	cout << s.length() << endl;
	
	cout << s.size() << endl;

	return 0;
}

/*
run:

15
15

*/

 



answered May 8, 2018 by avibootz

Related questions

1 answer 172 views
2 answers 210 views
2 answers 293 views
1 answer 150 views
1 answer 139 views
1 answer 232 views
232 views asked Oct 16, 2020 by avibootz
...