Avatar of RunBoris
RunBoris asked on

Read from Unicode Text Files

I made this nifty app in C++ using standard resources like iostream and fstream, which takes a text playlist from itunes, finds all the songs anywhere on the hard drive, and copies them to one folder (to be put on a CD, flash drive, etc.). Well, apparently up until a month or so ago, these text files were saved as ANSI; now they are saved by iTunes as Unicode. I don't know if its UTF-8, 16, 32 or what. All I know is now my app won't work unless I open the text file and save it as an ANSI text file.

So my question is, what is the simplest way to enable the reading of unicode files? It would be really awesome if there was a header/class file out there that made it as easy as replacing ifstream.get with utfstream.get or something to that effect. Thanks a bunch!
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
#include <IO.h>
#include <stdexcept>
int main()
{
    ifstream inList;
    inList.get(st_list.s_Name, MAX_STRING, '\t');

Open in new window

C++Programming Languages-Other

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
LordOfPorts

Try using wifstream http://msdn.microsoft.com/en-us/library/3b5w4311(VS.80).aspx instead of ifstream, you will also have to switch from char to wchar_t for the s_Name member variable in order to accomodate Unicode characters.
ASKER
RunBoris

Alright, I'm not sure I understand from the MSDN site about how to utilize this. (Sorry, I'm still in school trying to learn this stuff.)

I replaced all instances of ifstream with wifstream, including my void functions declarations, and it gave me errors about everything in my functions not being "declared in this scope." What did I not do properly?
LordOfPorts

Have you also replaced char with wchar_t for various variables? Can you post more of your code?
Your help has saved me hundreds of hours of internet surfing.
fblack61
evilrix

If the files have one, you might be able to use the Byte Order Mark to try and figure out whether it's UTF 8/16/32. If it's UTF32 you'll have a small problem on Windows in so far as wchar_t on Windows is 16 bit. I think you'd be better off reading the data in as bytes, figuring out what formats in and if it's in UTF16 or 32 convert it to UTF8 and handle it in that format internally. That way you won't have to modify all your code to use wchar_t... it's not necessary if you use UTF8. Also, since ANSI is a subset of UTF8 your code will be backwards compatible with older files.

http://en.wikipedia.org/wiki/Byte-order_mark

You can use the mbstowcs and wcstombs to convert between wide and narrow strings.
http://www.cplusplus.com/reference/clibrary/cstdlib/wcstombs.html
http://www.cplusplus.com/reference/clibrary/cstdlib/mbstowcs.html
evilrix

>> I replaced all instances of ifstream with wifstream
This isn't necessary if you read the data in as raw bytes, figure out the format and then convert it to UTF8 as required.

BTW: There is a misconception that Unicode is synonymous with characters are wide, this is not true. Wide characters allows you to represent wide format Unicode Transformation Formats (UTF16/32), but you can also use narrow (UTF8) without the need to resort to wide. Also, what Microsoft calls Unicode is actually just UTF16. A Unicode character is a code-point and it is always 32 bit.

http://en.wikipedia.org/wiki/UTF-8
http://en.wikipedia.org/wiki/UTF-16
http://en.wikipedia.org/wiki/UTF-32
ASKER
RunBoris

Yes, LordOfPorts, I did replace all the char istances with wchar_t. The problem is related to wifstream I believe, because the comilers stops with errors at the void function declarations, not ata the wchar_t variable declarations. Here's some code for you.

Like I said, the compiler stops at the first VOID statement.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
#include <IO.h>
#include <stdexcept>
 
using namespace std;
 
const int MAX_STRING = 400;
 
struct listType
{
       wchar_t s_Name[MAX_STRING];
       wchar_t s_Artist[MAX_STRING];
       wchar_t s_Discard[MAX_STRING];
       wchar_t s_Album[MAX_STRING];
       //char s_Grouping[MAX_STRING];
       //char s_Genre[MAX_STRING];
       //char s_Size[MAX_STRING];
       //char s_Time[MAX_STRING];
       //char s_Disc_Number[MAX_STRING];
       //char s_Disc_Count[MAX_STRING];
       wchar_t s_Track_Number[MAX_STRING];
       //char s_Track_Count[MAX_STRING];
       wchar_t s_Year[MAX_STRING];
       //char s_Date_Modified[MAX_STRING];
       //char s_Date_Added[MAX_STRING];
       //char s_Bitrate[MAX_STRING];
       //char s_Sample_Rate[MAX_STRING];
       //char s_Volume_Adjustment[MAX_STRING];
       //char s_Kind[MAX_STRING];
       //char s_Equalizer[MAX_STRING];
       //char s_Comments[MAX_STRING];
       //char s_Play_Count[MAX_STRING];
       //char s_Last_Played[MAX_STRING];
       //char s_Skip_Count[MAX_STRING];
       //char s_Last_Skipped[MAX_STRING];
       //char s_My_Rating[MAX_STRING];
       wchar_t s_Location[MAX_STRING];
};
 
void readList(wifstream& inList, ofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copyFile(wifstream& inList, ofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copy_file(std::string const & sOldPath, std::string const & sNewPath);
void errorQuit(int errorNumber);
 
int main()

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
LordOfPorts

Try adding at the top:

#include <iosfwd>

The ofstream reference parameter should also be replaced with wofstream in the function declarations and definitions. Also any cout/cin should become wcout/wcin

evilrix also posted some very useful information regarding the Unicode strings; from reading few similar postings related to the iTunes playlist files and the recent encoding change some people were able to fix it by saving the file as Unicode in Windows implicitly indicating that it is probably UTF-16 encoding so wchar_t might resolve the issue. Give it a try with the include above and we will proceed from there.
evilrix

>> The problem is related to wifstream I believe, because the comilers stops with errors at the void function declarations
And what are the errors?
ASKER
RunBoris

I'm still getting the same "...was not declared in this scope" for all parts of the void declarations.
57 C:\Kopy iTunes Songs\kits.cpp `wifstream' was not declared in this scope 
57 C:\Kopy iTunes Songs\kits.cpp `inList' was not declared in this scope 
57 C:\Kopy iTunes Songs\kits.cpp `wofstream' was not declared in this scope 
 
And so on...

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
LordOfPorts

Are you using gcc to compile the project? From reading about the error, http://www.cs.uwm.edu/~cs351/faq/compiler-errors.html (lookup word 'scope'), it appears to be related to the order of include files. It compiles fine in Visual Studio so I am not certain what exactly is the issue. How are your files structured and what compile command do you issue to create the executable?
evilrix

The code snippet also compiles fine on gcc4.1.2 (after removing IO.h).
ASKER
RunBoris

I'm using Dev C++. Do I need some kind of addon pack to make this work properly?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
LordOfPorts

Dev C++ is the IDE that uses a GCC based compiler and there would have presumably been an error if one of the included libraries could not be found; it is more likely that the compiler encounters code prior to including the appropriate include needed for the code. How are your files structured, i.e. please outline the .h and .cpp files you have and what are the include directives for each?
ASKER
RunBoris

Ok, I'm not exactly sure what you're asking for, so I think I'm going to post my entire code thing. Its not like I'm trying to sell it, so we'll call it free license. :)
I haven't changed any of the #included files at all; they were all originals.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iosfwd>
#include <string>
#include <cstdlib>
#include <IO.h>
#include <stdexcept>
 
using namespace std;
 
const int MAX_STRING = 400;
 
struct listType
{
       wchar_t s_Name[MAX_STRING];
       wchar_t s_Artist[MAX_STRING];
       wchar_t s_Discard[MAX_STRING];
       wchar_t s_Album[MAX_STRING];
       //char s_Grouping[MAX_STRING];
       //char s_Genre[MAX_STRING];
       //char s_Size[MAX_STRING];
       //char s_Time[MAX_STRING];
       //char s_Disc_Number[MAX_STRING];
       //char s_Disc_Count[MAX_STRING];
       wchar_t s_Track_Number[MAX_STRING];
       //char s_Track_Count[MAX_STRING];
       wchar_t s_Year[MAX_STRING];
       //char s_Date_Modified[MAX_STRING];
       //char s_Date_Added[MAX_STRING];
       //char s_Bitrate[MAX_STRING];
       //char s_Sample_Rate[MAX_STRING];
       //char s_Volume_Adjustment[MAX_STRING];
       //char s_Kind[MAX_STRING];
       //char s_Equalizer[MAX_STRING];
       //char s_Comments[MAX_STRING];
       //char s_Play_Count[MAX_STRING];
       //char s_Last_Played[MAX_STRING];
       //char s_Skip_Count[MAX_STRING];
       //char s_Last_Skipped[MAX_STRING];
       //char s_My_Rating[MAX_STRING];
       wchar_t s_Location[MAX_STRING];
};
 
void readList(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copyFile(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copy_file(std::string const & sOldPath, std::string const & sNewPath);
void errorQuit(int errorNumber);
 
int main()
{
    wifstream inList;
    wofstream outLog;
    inList.open("playlist.txt");
    outLog.open("KiTS_Log.txt");
    int cntGood = 0, cntBad = 0;
    listType st_list;
    if (!inList)
       errorQuit(1);
    else
    {
        wcout << "File copy in progress.";
        readList(inList, outLog, st_list, cntGood, cntBad);
    }
    
    inList.close();
    wcout << endl << endl;
    outLog << endl << endl;
    wcout << "Successfully copied " << cntGood << " files!\n";
    outLog << "Successfully copied " << cntGood << " files!\n";
    if (cntBad > 0)
    {
       wcout << cntBad << " files failed to copy. See errors above...\n";
       outLog << cntBad << " files failed to copy. See errors above...\n";
    }
    else
    {
        wcout << "There were no errors during copying!\n";
        outLog << "There were no errors during copying!\n";
    }
    wcout << endl;
    outLog.close();
 
    system("PAUSE");
    return 0;
}
 
void readList(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
     char discard;
     inList.ignore(1000, '\n');
     int i = 0;
     bool bEOF = false;
     while (bEOF == false)
     {
         inList.get(st_list.s_Name, MAX_STRING, '\t');
         inList.get(discard);
         
         wcout << st_list.s_Name << endl;
 
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Artist, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Album, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Track_Number, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Year, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {    
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
 
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }    
         
         inList.get(st_list.s_Location, MAX_STRING, '\n');
         
         inList.get(discard);
         inList.get(discard);
                  
         copyFile(inList, outLog, st_list, cntGood, cntBad);
         
         if (inList.eof())
            bEOF = true;
         else
             inList.putback(discard);
     }
}
 
void copyFile(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
     char strSRC[MAX_STRING], strDST[MAX_STRING], c_ext[5];
     strcpy(strSRC, st_list.s_Location);
     for (int q = 0; q < MAX_STRING; q++)
     {
         if (strSRC[q] == '\0')
         {
            c_ext[0] = strSRC[q-4];
            c_ext[1] = strSRC[q-3];
            c_ext[2] = strSRC[q-2];
            c_ext[3] = strSRC[q-1];
            break;
         }
     }
     strcpy(strDST, st_list.s_Artist);
     strcat(strDST, " - ");
     strcat(strDST, st_list.s_Name);
     strcat(strDST, c_ext);
     string s = strDST;
     int x = s.find(":",3);
     while (x > 3)
     {
           s.replace(x, 1, "-");
           x = s.find(":",3);
     }
     x = s.find("/",3);
     while (x > 3)
     {
           s.replace(x, 1, "-");
           x = s.find("/",3);
     }
     x = s.find("*",3);
     while (x > 3)
     {
           s.replace(x, 1, "_");
           x = s.find("*",3);
     }
     x = s.find("?",3);
     while (x > 3)
     {
           s.replace(x, 1, "");
           x = s.find("*",3);
     }
     strcpy(strDST, s.c_str());
     
     try
     {
             copy_file(strSRC, strDST);
             wcout << ".";
             outLog << st_list.s_Name << ":\n" << "---SUCCESS!\n";
             cntGood++;
     }
     catch(std::exception const & ex)
             {
             std::cerr << endl << "Error. " << ex.what() << endl << st_list.s_Name << endl;
             outLog << st_list.s_Name << ":\n" << "---FAILURE!\n";
             cntBad++;
             }
}
 
void copy_file(std::string const & sOldPath, std::string const & sNewPath)
{
        std::ifstream ifs(sOldPath.c_str(), std::ios::binary);
        if(!ifs.is_open()) { throw std::runtime_error("Unable to open input file:"); }
 
        std::ofstream ofs(sNewPath.c_str(), std::ios::trunc | std::ios::binary);
        if(!ofs.is_open()) { throw std::runtime_error("Unable to open output file:"); }
 
        ifs.seekg(0, std::ios::end);
        std::ifstream::pos_type size = ifs.tellg();
        ifs.seekg(0);
 
        std::string sData(size, std::string::value_type());
 
        ifs.read(&sData[0], size);
        if(!ifs.good()) { throw std::runtime_error("Unable to read input file:"); }
 
        ofs.write(sData.data(), size);
        if(!ifs.good()) { throw std::runtime_error("Unable to write output file:"); }
}
 
 
void errorQuit(int errorNumber)
{
     switch (errorNumber)
     {
            case 1:
                 cout << "There was an error opening \"playlist.txt\". Now terminating...\n";
                 break;
            default:
                    cout << "An unknown error has occured. Now terminating...\n";
                    break;
     }
}

Open in new window

ASKER
RunBoris

//Boost points because I think I'm being a burden.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
evilrix

>> I'm using Dev C++. Do I need some kind of addon pack to make this work properly?
Ok, well you had a right old mix of wide and narrow so I've converted everything that needs to be converted for it to build to be wide as best I can. I can't, though, test this so consider it best endeavors.

I'd urge you again to consider if you really need to convert all your code to wide. See what I posted above, read it carefully, it's just not necessary! Wide implies you want to use UTF16/32, but you can keep all your code as it is and just convert to UTF8... I honestly believe this would be a much simpler solution and also it'd be backwards compatible. Is there any reason you don't want to just handle this as UTF8? You'd save yourself a lot of pain. Coding wide can be very painful!
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iosfwd>
#include <string>
#include <cstdlib>
//#include <IO.h>
#include <stdexcept>
 
using namespace std;
 
const int MAX_STRING = 400;
 
struct listType
{
	wchar_t s_Name[MAX_STRING];
	wchar_t s_Artist[MAX_STRING];
	wchar_t s_Discard[MAX_STRING];
	wchar_t s_Album[MAX_STRING];
	//char s_Grouping[MAX_STRING];
	//char s_Genre[MAX_STRING];
	//char s_Size[MAX_STRING];
	//char s_Time[MAX_STRING];
	//char s_Disc_Number[MAX_STRING];
	//char s_Disc_Count[MAX_STRING];
	wchar_t s_Track_Number[MAX_STRING];
	//char s_Track_Count[MAX_STRING];
	wchar_t s_Year[MAX_STRING];
	//char s_Date_Modified[MAX_STRING];
	//char s_Date_Added[MAX_STRING];
	//char s_Bitrate[MAX_STRING];
	//char s_Sample_Rate[MAX_STRING];
	//char s_Volume_Adjustment[MAX_STRING];
	//char s_Kind[MAX_STRING];
	//char s_Equalizer[MAX_STRING];
	//char s_Comments[MAX_STRING];
	//char s_Play_Count[MAX_STRING];
	//char s_Last_Played[MAX_STRING];
	//char s_Skip_Count[MAX_STRING];
	//char s_Last_Skipped[MAX_STRING];
	//char s_My_Rating[MAX_STRING];
	wchar_t s_Location[MAX_STRING];
};
 
void readList(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copyFile(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
//void copy_file(std::string const & sOldPath, std::string const & sNewPath); //<--- RX: NEedds to ne wstring
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath);
void errorQuit(int errorNumber);
 
int main()
{
	wifstream inList;
	wofstream outLog;
	inList.open("playlist.txt");
	outLog.open("KiTS_Log.txt");
	int cntGood = 0, cntBad = 0;
	listType st_list;
	if (!inList)
		errorQuit(1);
	else
	{
		wcout << "File copy in progress.";
		readList(inList, outLog, st_list, cntGood, cntBad);
	}
 
	inList.close();
	wcout << endl << endl;
	outLog << endl << endl;
	wcout << "Successfully copied " << cntGood << " files!\n";
	outLog << "Successfully copied " << cntGood << " files!\n";
	if (cntBad > 0)
	{
		wcout << cntBad << " files failed to copy. See errors above...\n";
		outLog << cntBad << " files failed to copy. See errors above...\n";
	}
	else
	{
		wcout << "There were no errors during copying!\n";
		outLog << "There were no errors during copying!\n";
	}
	wcout << endl;
	outLog.close();
 
	system("PAUSE");
	return 0;
}
 
void readList(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
	//char discard; // <--- RX: THis needs to be wchar_t
	wchar_t discard;
	inList.ignore(1000, '\n');
	int i = 0;
	bool bEOF = false;
	while (bEOF == false)
	{
		inList.get(st_list.s_Name, MAX_STRING, '\t');
		inList.get(discard);
 
		wcout << st_list.s_Name << endl;
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Artist, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Album, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Track_Number, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Year, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{    
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}    
 
		inList.get(st_list.s_Location, MAX_STRING, '\n');
 
		inList.get(discard);
		inList.get(discard);
 
		copyFile(inList, outLog, st_list, cntGood, cntBad);
 
		if (inList.eof())
			bEOF = true;
		else
			inList.putback(discard);
	}
}
 
void copyFile(wifstream& inList, wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
	//char strSRC[MAX_STRING], strDST[MAX_STRING], c_ext[5]; //<--- RX: Needs to be wchar_t
	wchar_t strSRC[MAX_STRING], strDST[MAX_STRING], c_ext[5];
	//strcpy(strSRC, st_list.s_Location); // RX: Needs to be wcscpy
	wcscpy(strSRC, st_list.s_Location);
	for (int q = 0; q < MAX_STRING; q++)
	{
		if (strSRC[q] == '\0')
		{
			c_ext[0] = strSRC[q-4];
			c_ext[1] = strSRC[q-3];
			c_ext[2] = strSRC[q-2];
			c_ext[3] = strSRC[q-1];
			break;
		}
	}
	//strcpy(strDST, st_list.s_Artist); //<--- RX: Needs to be wcscpy
	wcscpy(strDST, st_list.s_Artist);
	//strcat(strDST, " - "); //<--- RX: Needs to be wcscat and wide for param 2
	wcscat(strDST, L" - ");
	//strcat(strDST, st_list.s_Name); //<--- RX: Needs to be wcscat
	wcscat(strDST, st_list.s_Name);
	//strcat(strDST, c_ext); //<--- RX: Needs to be wcscat
	wcscat(strDST, c_ext);
	//string s = strDST; //<--- RX: Needs to be a wide string
	wstring s = strDST;
	// int x = s.find(":",3); //<--- RX: Needs to be wide char
	int x = s.find(L":",3);
	while (x > 3)
	{
		//s.replace(x, 1, "-"); //<--- RX: Needs to be wide char
		s.replace(x, 1, L"-");
		//x = s.find(":",3); //<--- RX: Needs to be wide char
		x = s.find(L":",3);
	}
	//x = s.find("/",3); //<--- RX: Needs to be wide char
	x = s.find(L"/",3);
	while (x > 3)
	{
		//s.replace(x, 1, "-"); //<--- RX: Needs to be wide char
		s.replace(x, 1, L"-");
		//x = s.find("/",3); //<--- RX: Needs to be wide char
		x = s.find(L"/",3);
	}
	//x = s.find("*",3); //<--- RX: Needs to be wide char
	x = s.find(L"*",3);
	while (x > 3)
	{
		//s.replace(x, 1, "_"); //<--- RX: Needs to be wide char
		s.replace(x, 1, L"_");
		//x = s.find("*",3); //<--- RX: Needs to be wide char
		x = s.find(L"*",3);
	}
	//x = s.find("?",3); //<--- RX: Needs to be wide char
	x = s.find(L"?",3);
	while (x > 3)
	{
		//s.replace(x, 1, ""); //<--- RX: Needs to be wide char
		s.replace(x, 1, L"");
		//x = s.find("*",3); //<--- RX: Needs to be wide char
		x = s.find(L"*",3);
	}
	//strcpy(strDST, s.c_str()); //<--- RX: Needs to be wcscpy
	wcscpy(strDST, s.c_str());
 
	try
	{
		copy_file(strSRC, strDST);
		wcout << "."; //<--- RX: Needs to be wide char
		outLog << st_list.s_Name << ":\n" << "---SUCCESS!\n"; //<--- RX: Needs to be wide char
		cntGood++;
	}
	catch(std::exception const & ex)
	{
		std::cerr << endl << "Error. " << ex.what() << endl << st_list.s_Name << endl; //<--- RX: Needs to be wide char
		outLog << st_list.s_Name << ":\n" << "---FAILURE!\n"; //<--- RX: Needs to be wide char
		cntBad++;
	}
}
 
//void copy_file(std::string const & sOldPath, std::string const & sNewPath) // <--- RX: Needs to be wstring
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath)
{
	std::string s; // RX: Used to conert from wide to narrow
 
	// std::ifstream ifs(sOldPath.c_str(), std::ios::binary); // <---RX: wide stream
	s.resize(sOldPath.size() * 4);
	wcstombs (&s[0], sOldPath.c_str(), s.size());
	std::wifstream ifs(s.c_str(), std::ios::binary);
	if(!ifs.is_open()) { throw std::runtime_error("Unable to open input file:"); }
 
	//std::ofstream ofs(sNewPath.c_str(), std::ios::trunc | std::ios::binary); // <---RX: wide stream
	s.resize(sNewPath.size() * 4);
	wcstombs (&s[0], sNewPath.c_str(), s.size());
	std::wofstream ofs(s.c_str(), std::ios::trunc | std::ios::binary);
	if(!ofs.is_open()) { throw std::runtime_error("Unable to open output file:"); }
 
	ifs.seekg(0, std::ios::end);
	std::ifstream::pos_type size = ifs.tellg();
	ifs.seekg(0);
 
	//std::string sData(size, std::string::value_type()); /./ <--- RX:Wide string
	std::wstring sData(size, std::wstring::value_type());
 
	ifs.read(&sData[0], size);
	if(!ifs.good()) { throw std::runtime_error("Unable to read input file:"); }
 
	ofs.write(sData.data(), size);
	if(!ifs.good()) { throw std::runtime_error("Unable to write output file:"); }
}
 
 
void errorQuit(int errorNumber)
{
	switch (errorNumber)
	{
	case 1:
		cout << "There was an error opening \"playlist.txt\". Now terminating...\n";
		break;
	default:
		cout << "An unknown error has occured. Now terminating...\n";
		break;
	}
}

Open in new window

evilrix

^^^BTW I commented all my changes so you can see what I did.
ASKER
RunBoris

I still get the same scope errors using the changes (copy-pasted the entire thing). Now, I'm not specifically trying to utilize UTF16/32. If UTF8 is easier, I'll certainly use that. The only worry I have is how iTunes will export the playlist text file. If it uses UTF8, then I'm all set. I guess the overall problem is that I don't know how to read the new(er) unicode format that iTunes saves in. Anything that works properly, I'll have no quarel with.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
LordOfPorts

I cannot confirm it but again from reading few postings the iTunes playlist files seem to be UTF-16 encoded, e.g. an excerpt from http://gwhiz.wordpress.com/2008/01/08/itunes-producer-under-the-hood/ 

"Importing data from a tab-delimited file
You can import playlist and track data from a tab-delimited file instead of hand entering the data. Your data must be contained in a tab-delimited (encoded in UTF-16 format) file."

I had also converted the code in the code snippet below but I am not certain if it will work either on your end, it compiled successfully in Visual Studio. Perhaps check the version of the IDE you are using and see if there is a newer one. You might also perhaps try a new simple project whereby you would open a wifstream and maybe just read the first segment of the file and display it on the screen to see if that would compile on your end.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iosfwd>
#include <string>
#include <cstdlib>
#include <IO.h>
#include <stdexcept>
 
const int MAX_STRING = 400;
 
struct listType
{
       wchar_t s_Name[MAX_STRING];
       wchar_t s_Artist[MAX_STRING];
       wchar_t s_Discard[MAX_STRING];
       wchar_t s_Album[MAX_STRING];
       //char s_Grouping[MAX_STRING];
       //char s_Genre[MAX_STRING];
       //char s_Size[MAX_STRING];
       //char s_Time[MAX_STRING];
       //char s_Disc_Number[MAX_STRING];
       //char s_Disc_Count[MAX_STRING];
       wchar_t s_Track_Number[MAX_STRING];
       //char s_Track_Count[MAX_STRING];
       wchar_t s_Year[MAX_STRING];
       //char s_Date_Modified[MAX_STRING];
       //char s_Date_Added[MAX_STRING];
       //char s_Bitrate[MAX_STRING];
       //char s_Sample_Rate[MAX_STRING];
       //char s_Volume_Adjustment[MAX_STRING];
       //char s_Kind[MAX_STRING];
       //char s_Equalizer[MAX_STRING];
       //char s_Comments[MAX_STRING];
       //char s_Play_Count[MAX_STRING];
       //char s_Last_Played[MAX_STRING];
       //char s_Skip_Count[MAX_STRING];
       //char s_Last_Skipped[MAX_STRING];
       //char s_My_Rating[MAX_STRING];
       wchar_t s_Location[MAX_STRING];
};
 
void readList(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copyFile(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath);
void errorQuit(int errorNumber);
 
int main()
{
	std::wifstream inList;
	std::wofstream outLog;
    inList.open("playlist.txt");
    outLog.open("KiTS_Log.txt");
    int cntGood = 0, cntBad = 0;
    listType st_list;
	if (!inList.is_open())
       errorQuit(1);
    else
    {
		std::cout << "File copy in progress.";
        readList(inList, outLog, st_list, cntGood, cntBad);
    }
    
    inList.close();
	std::cout << std::endl << std::endl;
	outLog << std::endl << std::endl;
	std::cout << "Successfully copied " << cntGood << " files!\n";
    outLog << L"Successfully copied " << cntGood << L" files!\n";
    if (cntBad > 0)
    {
		std::cout << cntBad << " files failed to copy. See errors above...\n";
        outLog << cntBad << L" files failed to copy. See errors above...\n";
    }
    else
    {
		std::cout << "There were no errors during copying!\n";
        outLog << L"There were no errors during copying!\n";
    }
	std::cout << std::endl;
    outLog.close();
 
    system("PAUSE");
    return 0;
}
 
void readList(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
     wchar_t discard;
     inList.ignore(1000, '\n');
     int i = 0;
     bool bEOF = false;
     while (bEOF == false)
     {
         inList.get(st_list.s_Name, MAX_STRING, '\t');
         inList.get(discard);
         
		 std::cout << st_list.s_Name << std::endl;
 
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Artist, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Album, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Track_Number, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Year, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         inList.get(st_list.s_Discard, MAX_STRING, '\t');
         inList.get(discard);
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {    
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
 
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {         
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }
         
         if (inList.peek() == 9)
            inList.ignore(200, '\t');
         else
         {
             inList.get(st_list.s_Discard, MAX_STRING, '\t');
             inList.get(discard);
         }    
         
         inList.get(st_list.s_Location, MAX_STRING, '\n');
         
         inList.get(discard);
         inList.get(discard);
                  
         copyFile(inList, outLog, st_list, cntGood, cntBad);
         
         if (inList.eof())
            bEOF = true;
         else
             inList.putback(discard);
     }
}
 
void copyFile(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
     wchar_t strSRC[MAX_STRING], strDST[MAX_STRING], c_ext[5];
     wcscpy(strSRC, st_list.s_Location);
     for (int q = 0; q < MAX_STRING; q++)
     {
         if (strSRC[q] == '\0')
         {
            c_ext[0] = strSRC[q-4];
            c_ext[1] = strSRC[q-3];
            c_ext[2] = strSRC[q-2];
            c_ext[3] = strSRC[q-1];
            break;
         }
     }
     wcscpy(strDST, st_list.s_Artist);
     wcscat(strDST, L" - ");
     wcscat(strDST, st_list.s_Name);
     wcscat(strDST, c_ext);
	 std::wstring s = strDST;
     size_t x = s.find(L":",3);
     while (x > 3)
     {
           s.replace(x, 1, L"-");
           x = s.find(L":",3);
     }
     x = s.find(L"/",3);
     while (x > 3)
     {
           s.replace(x, 1, L"-");
           x = s.find(L"/",3);
     }
     x = s.find(L"*",3);
     while (x > 3)
     {
           s.replace(x, 1, L"_");
           x = s.find(L"*",3);
     }
     x = s.find(L"?",3);
     while (x > 3)
     {
           s.replace(x, 1, L"");
           x = s.find(L"*",3);
     }
     wcscpy(strDST, s.c_str());
     
     try
     {
             copy_file(strSRC, strDST);
			 std::cout << ".";
             outLog << st_list.s_Name << L":\n" << L"---SUCCESS!\n";
             cntGood++;
     }
     catch(exception const & ex)
     {
		 std::cerr << std::endl << "Error. " << ex.what() << std::endl << st_list.s_Name << std::endl;
         outLog << st_list.s_Name << L":\n" << L"---FAILURE!\n";
         cntBad++;
     }
}
 
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath)
{
		char * aOldPath = new char[255];
		sprintf(aOldPath, "%ls", sOldPath.c_str());
		std::wifstream ifs(aOldPath, std::ios::binary);
		if(!ifs.is_open()) { throw std::runtime_error("Unable to open input file:"); }
 
		char * aNewPath = new char[255];
		sprintf(aNewPath, "%ls", sNewPath.c_str());
		std::wofstream ofs(aNewPath, std::ios::trunc | std::ios::binary);
		if(!ofs.is_open()) { throw std::runtime_error("Unable to open output file:"); }
 
		ifs.seekg(0, std::ios::end);
		std::wifstream::pos_type size = ifs.tellg();
        ifs.seekg(0);
 
		std::wstring sData(size, std::wstring::value_type());
 
        ifs.read(&sData[0], size);
		if(!ifs.good()) { throw std::runtime_error("Unable to read input file:"); }
 
        ofs.write(sData.data(), size);
		if(!ifs.good()) { throw std::runtime_error("Unable to write output file:"); }
}
 
 
void errorQuit(int errorNumber)
{
     switch (errorNumber)
     {
            case 1:
				std::cout << "There was an error opening \"playlist.txt\". Now terminating...\n";
                 break;
            default:
				std::cout << "An unknown error has occured. Now terminating...\n";
                 break;
     }
}

Open in new window

ASKER CERTIFIED SOLUTION
itsmeandnobodyelse

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
RunBoris

Wow, ok here's what I got by comiling this in VS2003:
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(89): error C2297: '<<' : illegal, right operand has type 'const unsigned short [44]'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(67): error C2079: 'inList' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(68): error C2079: 'outLog' uses undefined class 'std::basic_ofstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(68) : see reference to class template instantiation 'std::basic_ofstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(68) : see reference to class template instantiation 'std::basic_ofstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(69): error C2039: 'open' : is not a member of 'System::Int32'
        stdafx.cpp(0) : see declaration of 'System::Int32'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(70): error C2039: 'open' : is not a member of 'System::Int32'
        stdafx.cpp(0) : see declaration of 'System::Int32'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(73): error C2039: 'is_open' : is not a member of 'System::Int32'
        stdafx.cpp(0) : see declaration of 'System::Int32'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(78): error C2664: 'readList' : cannot convert parameter 1 from 'int' to 'std::wifstream &'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(81): error C2039: 'close' : is not a member of 'System::Int32'
        stdafx.cpp(0) : see declaration of 'System::Int32'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(83): error C2563: mismatch in formal parameter list
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(83): error C2568: '<<' : unable to resolve function overload
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(928): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(920): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(896): or       'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(85): error C2297: '<<' : illegal, right operand has type 'const unsigned short [21]'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(85): error C2297: '<<' : illegal, right operand has type 'const unsigned short [9]'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(85): warning C4552: '<<' : operator has no effect; expected operator with side-effect
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(89): warning C4552: '<<' : operator has no effect; expected operator with side-effect
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(94): error C2297: '<<' : illegal, right operand has type 'const unsigned short [38]'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(94): warning C4552: '<<' : operator has no effect; expected operator with side-effect
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(97): error C2039: 'close' : is not a member of 'System::Int32'
        stdafx.cpp(0) : see declaration of 'System::Int32'
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(106): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(106) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(106): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(110): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(110) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(110): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(111): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(111) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(111): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(115): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(115) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(115): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(116): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(116) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(116): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(119): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(119) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(119): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(120): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(120) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(120): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(123): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(123) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(123): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(124): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(124) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(124): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(127): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(127) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(127): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(128): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(128) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(128): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(131): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(131) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(131): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(132): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(132) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(132): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(135): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(135) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(135): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(136): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(136) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(136): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(139): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(139) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(139): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(140): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(140) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(140): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(143): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(143) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(143): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(144): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(144) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(144): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(147): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(147) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(147): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(148): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(148) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(148): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(151): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(151) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(151): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(152): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(152) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(152): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(155): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(155) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(155): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(156): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(156) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(156): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(158): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(158) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(158): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(159): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(159) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(159): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(161): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(161) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(161): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(162): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(162) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(162): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(165): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(165) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(165): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(166): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(166) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(166): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(169): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(169) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(169): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(170): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(170) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(170): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(173): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(173) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(173): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(174): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(174) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(174): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(177): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(177) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(177): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(178): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(178) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(178): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(181): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(181) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(181): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(182): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(182) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(182): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(185): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(185) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(185): error C2228: left of '.peek' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(186): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(186) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(186): error C2228: left of '.ignore' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(189): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(189) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(189): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(190): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(190) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(190): error C2228: left of '.get' must have class/struct/union type
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(193): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        KiTS.cpp(193) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
c:\Users\RunBoris\Documents\Visual Studio Projects\KiTS\KiTS.cpp(193): fatal error C1003: error count exceeds 100; stopping compilation

Open in new window

evilrix

>> I still get the same scope errors using the changes (copy-pasted the entire thing).
Odd, the code compiled for me on both Windows and Linux without error... I wouldn't have posted it back to you otherwise :)

 Are you sure your dev environment is installed correctly? I remember working on a problem with another OP who was using dev-cpp and he too had problems using streams. I think we solved it in the end by him completely removing and reinstalling dev-cpp from scratch. I tried to find the thread but was unsuccessful. You could always try installing Visual Studio 2008 Express... it's what I used to get your code to build.

http://www.microsoft.com/express/download/

>> The only worry I have is how iTunes will export the playlist text file. If it uses UTF8, then I'm all set
Well, it's unlikely to be UTF8 because ASCII is a subset of UTF8 so your old code would probably still work. It's most likely, as LordOfPorts has identified, to be UTF16 (it's highly unlikely to be UTF32 as this wouldn't work natively on Windows without being converted to UTF16/8). So, this being the case all you need to do is read it in as a series of bytes and then pass the data to a Wide to Narrow conversion function. Windows has its own system functions for doing this, alternatively C++ provides functions too. See my posts {http:#21633836} and {http:#21633881} above for more info. Also see that Alex has given you a code snippet above {http:#21640652} for how you might do this.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
evilrix

>> Wow, ok here's what I got by comiling this in VS2003:
Um, that's not a managed code project is it?
"error C2039: 'open' : is not a member of 'System::Int32'"
System::Int32 is a managed code data type!

Were these errors from the code I posted you above? Building that code as native C++ compiles without error or warning (ignoring the lie about unsafe functions being deprecated of course!) using VS2005 Express, VS2008 Express and gcc4.1.2. Can you post back here the code you are trying to build if it's different please?
itsmeandnobodyelse

>>>> error C2079: 'inList' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'

as there was the #include <fstream>, it should know class 'std::basic_ifstream<_Elem,_Traits>'. So any of the other includes must make the definitions wrong.

I would suggest to drop

#include <cstdlib>
#include <IO.h>
#include <stdexcept>

as I can't see any use for them. Do you use any project macros or do you have precompiled headers via stdafx.h? Remove any selfly defined macros from C++ preprocessor settings. I also would suggest to switch off precompiled headers as there is no benefit using them (for non-MFC or small projects).

>>>> error C2297: '<<' : illegal, right operand has type 'const unsigned short [44]'

That is a following error because the ifstream/cout wasn't recognized as a valid class.

Did you made the project a UNICODE project? If yes, switch all settings off for UNICODE cause it makes your life unhappy when trying to handle plain ANSI or ASCII with a unicode enabled VC project.


Can you show *all* code of the cpp ?
itsmeandnobodyelse

>>>> Um, that's not a managed code project is it?

Good catch, Rix ;-)

Boris, managed C++ actually is a different language. You won't get the STL working with managed C++.

Create a new project in Visual Studio and choose an *empty* WIN32 console program. Then copy the cpp to the new project folder and add it by using the project tree (Add ... Existing Item ... after right-clocking on the project in the tree).

Regards, Alex
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
RunBoris

Right, that works now. It comiles in VS2K3 using that tip. However, something completely different is happening now. When the app runs, it does not read the playlist.txt file properly, and I honestly have no idea what's going wrong. It looks like when it tries to ready the first field (Song Title), it reads "0012D09C" for every song. Looks like the artists are all coming back as "0012D3BC". Not sure what all this means. I'm assuming there's a problem converting UTF16 to UTF8? But I don't understand how that would cause every playlist entry would give the same results for each field like that.
ASKER
RunBoris

I know for my original ANSI-TXT coding I was using character arrays. Did that possibly break when we switched it to wchar_t?
evilrix

That looks suspiciously like the value of a stack based pointer. Check your code to make sure you're not accidentally doing something wrong with an array causing you to use its address rather than the buffer it represents. If you're still stuck post the code here so we can build it along with a sample of your playlist file so we can test it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
RunBoris

Its a direct copy-paste from the modified code that LordOfPorts posted. I'll attach the playlist.txt file. I believe the only things that changed were the substitutions of wifstream/wofstream and wchar_t.
playlist.txt
evilrix

I think your problems go more deeper than just cosmetic... I get an access failure when I try to use the code, it looks like you are trying to use memory you don't own. I don't have time to debug it now, I'll try and look at it later or tomorrow. Meanwhile, maybe one of the other experts will have a little more time on their hands.
evilrix

Ok, you have 2 serious problems...

1) You have a buffer overrun in copyFile where you wcscat  your fixed size buffers because they end up not being null terminated. This is because (amongst other reasons) they are never initialized. Try initializing them so all elements are set to 0.

//wchar_t strSRC[MAX_STRING], strDST[MAX_STRING], c_ext[5];
wchar_t strSRC[MAX_STRING] = {0}, strDST[MAX_STRING] = {0}, c_ext[5] = {0};

Why don't you just use std::string rather than fixed size buffers?

2) Again in copyFile you are not handling the result of find correctly to you end up attempting to access invalid memory. The find function returns string::npos if it fails. You need to change you code so it makes sure the result of find is within the length of the string.

//while (x > 3)
while (x < s.size() && x > 3)

Also, the reason you are seeing strange hex numbers being output is because you are trying to write wide strings to a narrow output, you need to ensure all your output streams, where appropriate, are also wide.

//std::cerr << std::endl << "Error. " << ex.what() << std::endl << st_list.s_Name << std::endl;
std::cerr << std::endl << "Error. " << ex.what() << std::endl;
std::wcerr << st_list.s_Name << std::endl;

Below is you code where I've fixed these few issues. I'll have to let you test it as I have no files for it to process. I've only fixed obvious issues, I don't make any claims that this will work, but it might get you a little closer. I will say that the code is very messy and brittle and, to be brutally honest, could do with being rewritten from scratch! Also, again, I feel I should point out you are really going about this the hard way... there is just no need to convert your code to handle wide... just convert the data to mbcs on input as Alex has already shown you.

-Rx.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iosfwd>
#include <string>
#include <cstdlib>
#include <IO.h>
#include <stdexcept>
 
using namespace std;
 
const int MAX_STRING = 400;
 
struct listType
{
	wchar_t s_Name[MAX_STRING];
	wchar_t s_Artist[MAX_STRING];
	wchar_t s_Discard[MAX_STRING];
	wchar_t s_Album[MAX_STRING];
	//char s_Grouping[MAX_STRING];
	//char s_Genre[MAX_STRING];
	//char s_Size[MAX_STRING];
	//char s_Time[MAX_STRING];
	//char s_Disc_Number[MAX_STRING];
	//char s_Disc_Count[MAX_STRING];
	wchar_t s_Track_Number[MAX_STRING];
	//char s_Track_Count[MAX_STRING];
	wchar_t s_Year[MAX_STRING];
	//char s_Date_Modified[MAX_STRING];
	//char s_Date_Added[MAX_STRING];
	//char s_Bitrate[MAX_STRING];
	//char s_Sample_Rate[MAX_STRING];
	//char s_Volume_Adjustment[MAX_STRING];
	//char s_Kind[MAX_STRING];
	//char s_Equalizer[MAX_STRING];
	//char s_Comments[MAX_STRING];
	//char s_Play_Count[MAX_STRING];
	//char s_Last_Played[MAX_STRING];
	//char s_Skip_Count[MAX_STRING];
	//char s_Last_Skipped[MAX_STRING];
	//char s_My_Rating[MAX_STRING];
	wchar_t s_Location[MAX_STRING];
};
 
void readList(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copyFile(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad);
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath);
void errorQuit(int errorNumber);
 
int main()
{
	std::wifstream inList;
	std::wofstream outLog;
	inList.open("playlist.txt");
	outLog.open("KiTS_Log.txt");
	int cntGood = 0, cntBad = 0;
	listType st_list;
	if (!inList.is_open())
		errorQuit(1);
	else
	{
		std::cout << "File copy in progress.";
		readList(inList, outLog, st_list, cntGood, cntBad);
	}
 
	inList.close();
	std::cout << std::endl << std::endl;
	outLog << std::endl << std::endl;
	std::cout << "Successfully copied " << cntGood << " files!\n";
	outLog << L"Successfully copied " << cntGood << L" files!\n";
	if (cntBad > 0)
	{
		std::cout << cntBad << " files failed to copy. See errors above...\n";
		outLog << cntBad << L" files failed to copy. See errors above...\n";
	}
	else
	{
		std::cout << "There were no errors during copying!\n";
		outLog << L"There were no errors during copying!\n";
	}
	std::cout << std::endl;
	outLog.close();
 
	system("PAUSE");
	return 0;
}
 
void readList(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
	wchar_t discard;
	inList.ignore(1000, '\n');
	int i = 0;
	bool bEOF = false;
	while (bEOF == false)
	{
		inList.get(st_list.s_Name, MAX_STRING, '\t');
		inList.get(discard);
 
		//std::cout << st_list.s_Name << std::endl;
		std::wcout << st_list.s_Name << std::endl;
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Artist, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Album, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Track_Number, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Year, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		inList.get(st_list.s_Discard, MAX_STRING, '\t');
		inList.get(discard);
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{    
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{         
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}
 
		if (inList.peek() == 9)
			inList.ignore(200, '\t');
		else
		{
			inList.get(st_list.s_Discard, MAX_STRING, '\t');
			inList.get(discard);
		}    
 
		inList.get(st_list.s_Location, MAX_STRING, '\n');
 
		inList.get(discard);
		inList.get(discard);
 
		copyFile(inList, outLog, st_list, cntGood, cntBad);
 
		if (inList.eof())
			bEOF = true;
		else
			inList.putback(discard);
	}
}
 
void copyFile(std::wifstream& inList, std::wofstream& outLog, listType st_list, int& cntGood, int& cntBad)
{
	wchar_t strSRC[MAX_STRING] = {0}, strDST[MAX_STRING] = {0}, c_ext[5] = {0};
	wcscpy(strSRC, st_list.s_Location);
	for (int q = 0; q < MAX_STRING; q++)
	{
		if (strSRC[q] == '\0')
		{
			c_ext[0] = strSRC[q-4];
			c_ext[1] = strSRC[q-3];
			c_ext[2] = strSRC[q-2];
			c_ext[3] = strSRC[q-1];
			break;
		}
	}
	wcscpy(strDST, st_list.s_Artist);
	wcscat(strDST, L" - ");
	wcscat(strDST, st_list.s_Name);
	wcscat(strDST, c_ext);
	std::wstring s = strDST;
	size_t x = s.find(L":",3);
	while (x < s.size() && x > 3)
	{
		s.replace(x, 1, L"-");
		x = s.find(L":",3);
	}
	x = s.find(L"/",3);
	while (x < s.size() && x > 3)
	{
		s.replace(x, 1, L"-");
		x = s.find(L"/",3);
	}
	x = s.find(L"*",3);
	while (x < s.size() && x > 3)
	{
		s.replace(x, 1, L"_");
		x = s.find(L"*",3);
	}
	x = s.find(L"?",3);
	while (x < s.size() && x > 3)
	{
		s.replace(x, 1, L"");
		x = s.find(L"*",3);
	}
	wcscpy(strDST, s.c_str());
 
	try
	{
		copy_file(strSRC, strDST);
		std::cout << ".";
		outLog << st_list.s_Name << L":\n" << L"---SUCCESS!\n";
		cntGood++;
	}
	catch(exception const & ex)
	{
		std::cerr << std::endl << "Error. " << ex.what() << std::endl << st_list.s_Name << std::endl;
		outLog << st_list.s_Name << L":\n" << L"---FAILURE!\n";
		cntBad++;
	}
}
 
void copy_file(std::wstring const & sOldPath, std::wstring const & sNewPath)
{
	char * aOldPath = new char[255];
	sprintf(aOldPath, "%ls", sOldPath.c_str());
	std::wifstream ifs(aOldPath, std::ios::binary);
	if(!ifs.is_open()) { throw std::runtime_error("Unable to open input file:"); }
 
	char * aNewPath = new char[255];
	sprintf(aNewPath, "%ls", sNewPath.c_str());
	std::wofstream ofs(aNewPath, std::ios::trunc | std::ios::binary);
	if(!ofs.is_open()) { throw std::runtime_error("Unable to open output file:"); }
 
	ifs.seekg(0, std::ios::end);
	std::wifstream::pos_type size = ifs.tellg();
	ifs.seekg(0);
 
	std::wstring sData(size, std::wstring::value_type());
 
	ifs.read(&sData[0], size);
	if(!ifs.good()) { throw std::runtime_error("Unable to read input file:"); }
 
	ofs.write(sData.data(), size);
	if(!ifs.good()) { throw std::runtime_error("Unable to write output file:"); }
}
 
 
void errorQuit(int errorNumber)
{
	switch (errorNumber)
	{
	case 1:
		std::cout << "There was an error opening \"playlist.txt\". Now terminating...\n";
		break;
	default:
		std::cout << "An unknown error has occured. Now terminating...\n";
		break;
	}
}

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
RunBoris

Ok, I'll try the conversion method. It seems my original question of "can I just swap ifstream with something else" is not as easy as just swapping. I'll keep you posted. Thanks everyone!
evilrix

>> Ok, I'll try the conversion method.
I think it's worth a go, even if for no other reason that you rule it out... but I suspect it'll be simpler

>> It seems my original question of "can I just swap ifstream with something else" is not as easy as just swapping.
No, this was the point I tried to make initially

>> I'll keep you posted.
Sure thing.

>> Thanks everyone!
No worries.