Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The windows directory\ is used / replaced in actual development

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

# include try not to use\, but use /, so as to migrate the code to the Linux environment

The code is as follows:

# include "stdafx.h"

# include

# include

# include

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

}

Summary:

The first scheme uses the same slash as the Unix system, which is convenient to transplant to the Linux platform in the future development. after all, it is more troublesome to modify the slash in the header file include.

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

The second error scheme is analyzed in detail:

Split the 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 single-step debugging the actual content of szPathName becomes: the "E:docAndroidMakefile" compiler thinks that\ is used to prohibit escape, but does not expect that the user is actually used as a backslash, so it is cleared, resulting in a failure to read the file path.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report