Output String Data Summary using printf

Source: Internet
Author: User

# Include <stdio. h>

# Include <string. h>
Using namespace STD;
Int main ()
{
String;
A [0] = 'a ';
A [1] = '/0 ';
Printf ("% s/n", );
System ("pause ");
}

Error: [Warning] cannot pass objects of non-pod type 'struct STD: String 'pass'... '; call will abort at runtime

Printf can only Output Data Built-in C language, while string is not built-in, but an extended class. This is definitely a link error. String is not equal to char *. & A indicates the storage address of the string, not the first address of the string. The AA object contains a pointer to "string, & AAR obtains the address of this object, not the address of "string.

This operation should be performed on the string type output by printf!

# Include <iostream>
# Include <string>
Using namespace STD;

Void main ()
{
String AA = "qqq ";
Printf ("% s", AA. c_str (); // not recommended

// Or cout <;
}

Because string is an extension type of C, you can use the method provided by string to assign values to data: Assign (const char *) or directly use its constructor.
String STR ("Now is the time ...");

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.