Use C + to solve Chinese garbled characters in Linux

Source: Internet
Author: User

The problem is:
1. Use fstream to read Chinese files in Linux and store them in the string class.
2. Search, insert, replace, and append a string.
3. Use the SMTP protocol to send emails using the processed string.
4. The windows machine uses outlook to receive emails and finds several garbled characters in the body.

Continue to test the string class:
String text;
For (INT I = 0; I {
Text. append ("I ");
}
Sendmail (text );

Emails received by outlook on Windows machines are as follows:
Please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: when there are too many threads, there are too many threads, too many threads
Please refer to the following link for more information: please refer to the following link for more information: please refer to the following link for more information: when there are too many threads, there are too many threads, too many threads

It can be seen that there is a sudden line break in the middle. It may be that the string in Linux is not compatible with the Linux Encoding Process (or the Windows line feed is/R/N, and Linux is/N ). Run string. when append () is used, if the string class finds that the space is insufficient, it will request a larger memory to the operating system, copy the content to the new memory, and release the original memory, leading to garbled characters.

Solution:
1. Use notepad in Windows to edit the file content and save it as UTF-8 encoding format
2. upload files to Linux machines using Samba sharing
3. Read the file content into the cache using C in Linux. char *
4. Search, insert, replace, and append char * in the cache.
5. Convert the processed char * cache to the string class (string context (char *) and use the SMTP protocol to send emails (Sendmail (context ))
6. Windows machines use outlook to receive emails, and no garbled characters are found in the Chinese text.

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.