sizeof continues to return 4 instead of actual size

前端 未结 5 1141
孤街浪徒
孤街浪徒 2020-12-21 04:07
#include 

using namespace std;

int main()
{
    cout << \"Do you need to encrypt or decrypt?\" << endl;
    string message;
    getline         


        
5条回答
  •  感情败类
    2020-12-21 04:22

    class string
    {
        char * ptr;
        //...
        size_t size();  // return number of chars (until null) in buffer pointed to by ptr
    };
    
    sizeof(message) == sizeof(string) == sizeof(ptr) == 4; // size of the struct
    
    message.size() == number of characters in the message...
    

提交回复
热议问题