sizeof continues to return 4 instead of actual size

Posted by Guest on Stack Overflow See other posts from Stack Overflow or by Guest
Published on 2010-04-03T05:22:22Z Indexed on 2010/04/03 5:33 UTC
Read the original article Hit count: 338

Filed under:
|
#include <iostream>

using namespace std;

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

    int letter2number;

    for (int place = 1; place < sizeof(message); place++)
    {
        letter2number = static_cast<int>(message[place]);
        cout << letter2number << endl;
    }
}

Examples of problem: I type fifteen letters but only four integers are printed. I type seven letters but only four integers are printed.

The loop only occurs four times on my computer, not the number of characters in the string.

This is the only problem I am having with it, so if you see other errors, please don't tell me. (It is more fun that way.)

Thank you for your time.

© Stack Overflow or respective owner

Related posts about c++

Related posts about sizeof