#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