Ifstrem streams cannot be marked with IOS: app

Source: Internet
Author: User

The project is almost over. We took it last FridaySource codeDeploy at the customer's company.

Same copyCodeWith the old version of the GCC compiler, there is a bad precognition during compilation, and the compiledProgramThe execution result is incorrect.

After debugging in Linux for half a day, I finally reduced the problem to the following code line:

FS. Open (filepath, IOS: Binary | IOs: APP );

This FS is passed by the template parameters of the function, that is, it may be an input stream or an output stream, the main function of this part of the code is to verify whether the file to be opened is legal and to open the incoming file stream.

When the imported FS is an input stream, the open function of FS fails to be executed, that is, the specified file cannot be opened.

For the input stream, it only reads the content in the stream and does not need to append it. So I tried to remove the IOS: app tag, and the input stream can be opened normally.

Let's think about whether a function carries chaotic responsibilities. Only when the input stream opens this strange code in APP mode, we finally decide to extract a function separately by checking whether the file is legal, the caller maintains the opening of the file stream.

 

Conclusion: The GCC compiler of the old version imposes strict restrictions on the open mark of the input stream ifstream. Opening an input stream in APP mode will fail.

The GCC compiler of the latest version is more humane. Opening an input stream in APP mode does not cause a stream opening failure, but this app mode does not work for the input stream.

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.