Debug C ++ -- size_t type! = Int

Source: Internet
Author: User

As follows:Code:

String SA [6] = {"A1", "B2", "C3", "D4", "E5", "F6 "};

Vector <string> SVEC (SA, & SA [6]); // value assignment

Cout <"the value of SA [3] =" <SA [3] <Endl; // true

Cout <"the value of SVEC [3] =" <SVEC [3] <Endl; // error !!

I haven't seen the root cause of this error for a long time. Does vector have no index operator?

The next thought is wrong. As a sequential container, vector should have some basic operators with string objects.

The index value in the original vector must be of the size_t type.ProgramRun as follows!

Size_t Index = 3;

Cout <"the value of SVEC [3] =" <SVEC [Index] <Endl; // true !!

Therefore, you must be careful and careful in future operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.