当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How can I compare C-style strings?

问题描述:

This question already has an answer here:

  • Compare equality of char[] in C

    5 answers

网友答案:

You should use strcmp instead of == because the latter is merely a pointer comparison. Also, '\0' has to be used to end your string. And your current code would actually create an empty string because your string at position strlen(s) contains '\0'.

Then again, you should not work with char arrays in C++ on your own, rather use std::string as already pointed out in comments.

分享给朋友:
您可能感兴趣的文章:
随机阅读: