Experience Windows Catalog \ use/Replace in actual development

Source: Internet
Author: User

#include <boost\shared_ptr.hpp> try not to use \, but use/, this way to migrate code into the Linux environment

The code is as follows:

#include "stdafx.h"

#include <iostream>

#include <fstream>

#include <string>

using namespace Std;


int _tmain (int argc, _tchar* argv[])

{

Char utfbuffer[256] = {0};

Ifstream utffile ("E:/doc/android/makefile");//ok

Ifstream utffile ("E:\doc\Android\Makefile");//error

Ifstream utffile ("E:\\doc\\android\\makefile");//ok

Utffile.getline (Utfbuffer, 100);

size_t Inlen = strlen (Utfbuffer);

return 0;

}


Summarize:

The first scheme uses the same slash as the UNIX system, which facilitates porting to the Linux platform in future development, after all, the change of the slash in the header file include is more troublesome.

The third method uses a double backslash, which tells the compiler that the backslash is not used to mask escape, but is actually present.


The second type of error scenario, detailed analysis:

Split string:

Char utfbuffer[256] = {0};

Char szpathname[256] ={"E:\doc\Android\Makefile"};

Ifstream Utffile (szpathname);

Utffile.getline (Utfbuffer, 100);

size_t Inlen = strlen (Utfbuffer);

return 0;

By stepping through the actual contents of the Szpathname into: "e:docandroidmakefile" compiler think \ is used to prohibit escaping, and do not think that the user is actually as a backslash, so it clears, resulting in the read file path failed


Experience Windows Catalog \ use/Replace in actual development

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.