Jump to content

Help fopen


Go to solution Solved by Ken,

Recommended Posts

  • Solution
std::string GetFirstLineFromFile(std::string stFileName)
{
	std::ifstream file(stFileName.c_str(), std::ios::in);
	if (!file.is_open())
		return "Can not open the file";

	std::string stLine = "";
	if (!getline(file, stLine))
		return "Can not get the first line!";

	return stLine;
}

It will get the first line of the file. You can use this anywhere you want. (Don't forget to include fstream and string libraries)

Best Regards

Ken

Do not be sorry, be better.

Link to comment
Share on other sites

  • Premium

std::string GetExeFileName()
{
    char buffer[MAX_PATH];
    GetModuleFileName(NULL, buffer, MAX_PATH);
    return std::string(buffer);
}

std::string GetExePath()
{
    std::string f = GetExeFileName();
    return f.substr(0, f.find_last_of("\\/"));
}
 

    string baseLogDir = GetExePath();
    baseLogDir += "\\conta.txt";
    char* PubLogFile = _strdup(baseLogDir.c_str());

GetFirstLineFromFile("conta.txt")

or

GetFirstLineFromFile(PubLogFile)

client crash error ??????

 

thanks ken 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.