An experiment about coding (C # written Notepad document, read in C + + under Linux)

Source: Internet
Author: User



First step: Generate TXT documents in C # with various types of encoding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;

namespace WordTest
{
    class Program
    {
        static void Main (string [] args)
        {
            string text1 = "wa jue ji ji shu dao di na jia qiang? \ r \ n";
            string text2 = "Which digger technology is the best? \ r \ n";
            string text = text1 + text2;

            using (StreamWriter sw = new StreamWriter (
                "testASCII.txt", false, Encoding.ASCII))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.ASCII finished writing");
            }

            using (StreamWriter sw = new StreamWriter (
                "testBigEndianUnicode.txt", false, Encoding.BigEndianUnicode))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.BigEndianUnicode finished writing");
            }

            using (StreamWriter sw = new StreamWriter (
                "testUnicode.txt", false, Encoding.Unicode))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.Unicode finished writing");
            }

            using (StreamWriter sw = new StreamWriter (
                "testUTF32.txt", false, Encoding.UTF32))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.UTF32 finished writing");
            }

            using (StreamWriter sw = new StreamWriter (
                "testUTF7.txt", false, Encoding.UTF7))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.UTF7 finished writing");
            }

            using (StreamWriter sw = new StreamWriter (
                "testUTF8.txt", false, Encoding.UTF8))
            {
                sw.Write (text);
                Console.WriteLine ("Encoding.UTF8 finished writing");
            }

            Console.ReadLine ();
        }
    }
}


Program Run Result:






Step two: Copy to a redhat system and read the contents of these TXT documents with the cat command





Step three: read out the contents of these TXT documents in C + +



Program code:


#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream cin1("testASCII.txt");
    char s1a[100];
    char s1b[100];
    cin1.getline(s1a, 100, ‘\n‘);
    cin1.getline(s1b, 100, ‘\n‘);
    cout << "ASCII:" << endl << s1a << endl << s1b << endl << endl;

    ifstream cin2("testBigEndianUnicode.txt");
    char s2a[100];
    char s2b[100];
    cin2.getline(s2a, 100, ‘\n‘);
    cin2.getline(s2b, 100, ‘\n‘);
    cout << "BigEndianUnicode" << endl << s2a << endl << s2b << endl << endl;
    
    ifstream cin3("testUnicode.txt");
    char s3a[100];
    char s3b[100];
    cin3.getline(s3a, 100, ‘\n‘);
    cin3.getline(s3b, 100, ‘\n‘);
    cout << "Unicode" << endl << s3a << endl << s3b << endl << endl;

    ifstream cin4("testUTF32.txt");
    char s4a[100];
    char s4b[100];
    cin4.getline(s4a, 100, ‘\n‘);
    cin4.getline(s4b, 100, ‘\n‘);
    cout << "UTF32" << endl << s4a << endl << s4b << endl << endl;

    ifstream cin5("testUTF7.txt");
    char s5a[100];
    char s5b[100];
    cin5.getline(s5a, 100, ‘\n‘);
    cin5.getline(s5b, 100, ‘\n‘);
    cout << "UTF7" << endl << s5a << endl << s5b << endl << endl;

    ifstream cin6("testUTF8.txt");
    char s6a[100];
    char s6b[100];
    cin6.getline(s6a, 100, ‘\n‘);
    cin6.getline(s6b, 100, ‘\n‘);
    cout << "UTF8" << endl << s6a << endl << s6b << endl << endl;

    return 0;
}


Operation Result:





Conclusion: ASCII-encoded files can read English characters, UTF8 encoded files, C + + in Linux can read Chinese and English



END



An experiment about coding (C # written Notepad document, read in C + + under Linux)


Related Article

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.