开发者

Question about line.length();

开发者 https://www.devze.com 2023-01-20 10:46 出处:网络
does line.length();include end line chars? For example Hello World How long would this be 11 or开发者_Python百科 12?std::string s1 = \"Hello World\\n\";

does line.length(); include end line chars?

For example

Hello World

How long would this be 11 or开发者_Python百科 12?


std::string s1 = "Hello World\n";
std::cout << s1.length() << std::endl;

This prints 12. The new line is included in the length.


yes end line character( '\n') will be counted in the length.

std::string s = "Hello World";
std::cout<< s.length()<<std::endl;
s = "Hello World\n";
std::cout<<s.length()<<std::endl;

result will be

11
12

0

精彩评论

暂无评论...
验证码 换一张
取 消