Ejemplo n.º 1
0
wstring Player::toString() const
{
    wstring res = L"Player ";

    wchar_t buff[6];
    _swprintf(buff, 5, L"%d\n", m_id);
    res += wstring(buff);
    res += m_history.toString() + L"\n";
    res += L"score ";
    _swprintf(buff, 5, L"%d\n", getTotalScore());
    res += wstring(buff);
    return res;
}
Ejemplo n.º 2
0
int main()
{
	unsigned __int64 sum;
	sum ^= sum;
	std::ifstream FILE;
	char currchar;
	std::string currname;
	currname = "";
	std::vector<std::string> names;
	names.reserve(5000);

	try
	{
		FILE.open("names.txt", std::fstream::in); //read only, ios::in is no longer valid
		while(!FILE.eof())
		{
			//get line after line, each line goes to new string
			//doing it with strings is much easier than using a char array
			currchar = FILE.get();
			if(isalpha(currchar))
				currname.push_back(currchar);
			else
				if(!currname.empty())
				{
					names.push_back(currname);
					currname.clear();
				}
		}
		FILE.close();
	}
	catch(std::ifstream::failure e)
	{
		std::cerr << "Unable to open file.  Aborting program.\n";
		FILE.close();
		return 0;
	}

	//We have to define our own sort, as std::sort(RanIt begin, RanIt end) is a C++11 function
	std::sort(names.begin(),names.end(), userSortString);//std::greater<std::string>());  //built in sorts FTW!
	std::cout << "The total score of all the names in names.txt is " << getTotalScore(names) << std::endl;

	return 0;
}