C + + Primer after-school exercise 12.24//12.24.cpp: Defines the entry point for a console application.

Source: Internet
Author: User
12.24.cpp: Defines the entry point for the console application.
//


#include "stdafx.h"




#include <iostream>
#include <memory>
#include <string>


#pragma warning (disable:4996)


using namespace Std;


int main ()
{
String str;
cout << "Please enter a string:";
CIN >> str;
Char *CP = new Char[str.size () + 1]; This place must add 1, otherwise delete [] CP when error.
The actual length is longer than str.size () because STR.C_STR () returns a C-style string that ends with '.
strcpy (CP, STR.C_STR ()); This calls the C_STR () of the string object to return a C-style string.
_asserte (_CrtCheckMemory ()); Baidu there is a big God said you can use this to check what I said below the error.
cout << CP << Endl;
Delete[] CP;


return 0;


}

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.