http://stackoverflow.com/questions/8483472/include-skipped-when-looking-for-precompiled-header-use-unexpected-end-of-fi
Everything before the PCH is ignored by the compiler, therefore PCH must come first.
if you used precompiled headers you have to put it on the TOP, such as this:
#include "stdafx.h"
#include "String.h"
#include <iostream>
using namespace std;
#include <string.h>
You using the default MSVC project which includes precompiled headers. I would recommend selecting "Dont use precompiled headers option" when you make a project.
http://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c
inline bool is_file_exist(const char *fileName)
{
std::ifstream infile(fileName);
return infile.good();
}
The good method checks if the stream is ready to be read from.
This way you not only check if it exists & is readable, you actually open it.
inline bool exist(const std::string& name)
{
ifstream file(name);
if(!file) //if the file was not found, then file is 0, i.e. !file=1 or true
return false; //the file was not found
else //if the file was found, then file is non-0
return true; //the file was found
}
wstring.c_str()
std::wstring wc( cSize, L'#' );
mbstowcs( &wc[0], c, cSize );
How to: Convert Between Various String Types
http://msdn.microsoft.com/en-us/library/ms235631.aspx
char *orig = "Hello, World!";
size_t newsize = strlen(orig) + 1;
wchar_t * wcstring = new wchar_t[newsize];
// Convert char* string to a wchar_t* string.
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, newsize, orig, _TRUNCATE);
C++ String Literals
http://msdn.microsoft.com/en-us/library/69ze775t.aspx
Narrow string literals, represented as "xxx".
Wide string literals, represented as L"xxx".
Raw string literals, represented as R"ddd(xxx) ddd", where ddd is a delimiter. Raw string literals may be either narrow (represented with R) or wide (represented with LR).
const char *narrow = "abcd";
const wchar_t* wide = L"zyxw";
Input/output with files
http://www.cplusplus.com/doc/tutorial/files/
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
*How I can print the wchar_t values to console?*http://stackoverflow.com/questions/2493785/how-i-can-print-the-wchar-t-values-to-console
Use std::wcout instead of std::cout.
std::cout << "ASCII and ANSI" << std::endl;
std::wcout << L"INSERT MULTIBYTE WCHAR* HERE" << std::endl;
endl
Inserts a newline character into the output sequence and flush the output buffer.
Determines whether a path to a file system object such as a file or folder is valid.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773584(v=vs.85).aspx
#include <Shlwapi.h>
Add Library Shlwapi.lib by right clicking "Properties" -> "Configuration Properties" -> "Linker" -> "Input" -> "Additional Dependencies' -> "Edit" -> Shlwapi.lib
BOOL exist = PathFileExists(fileNameBuffer);
If you try to creat a file (that does not priviously exits) to use it for writing and reading using code like "fstream file("new_file",ios::out | ios::in) IT WON' T WORCK!!!!!!.
you have to create the file only for writing fstream file("new_file",ios::out) then close the file file.close() and now you can open it again this time for what ever operation you want , for exaple file.open("new_file",ios::out | ios::in | ios::binary) now it will work.
ifstream::open not working in Visual Studio debug mode
Visual Studio sets the working directory to YourProjectDirectory\Debug\Bin when running in debug mode. If your text file is in YourProjectDirectory, you need to account for that difference.