本文整理汇总了C++中ReadFromFile函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadFromFile函数的具体用法?C++ ReadFromFile怎么用?C++ ReadFromFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadFromFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_fragmentPath
Shader::Shader(const string vertexPath, const string fragmentPath):m_vertexPath(vertexPath) , m_fragmentPath(fragmentPath)
{
string vertexCode = ReadFromFile(vertexPath.c_str());
string fragmentCode = ReadFromFile(fragmentPath.c_str());
const char* tempChar;
GLuint vertexId;
GLuint fragmentId;
vertexId = glCreateShader(GL_VERTEX_SHADER);
tempChar = vertexCode.c_str();
glShaderSource(vertexId, 1, &tempChar, NULL);
glCompileShader(vertexId);
CheckCompileState(vertexId , GL_COMPILE_STATUS, "VERTEX");
fragmentId = glCreateShader(GL_FRAGMENT_SHADER);
tempChar = fragmentCode.c_str();
glShaderSource(fragmentId, 1, &tempChar, NULL);
glCompileShader(fragmentId);
CheckCompileState(fragmentId, GL_COMPILE_STATUS, "FRAGMENT");
this->m_shaderId = glCreateProgram();
glAttachShader(this->m_shaderId, vertexId);
glAttachShader(this->m_shaderId, fragmentId);
glLinkProgram(this->m_shaderId);
CheckCompileState(m_shaderId, GL_LINK_STATUS, "SHADER_PROGRAM");
glDeleteShader(vertexId);
glDeleteShader(fragmentId);
}
示例2: AG_ReadNotes
std::string AG_ReadNotes( filehandle refNum )
{
// File notes
std::ostringstream notes; notes << "\0";
AXGLONG notes_size = 0;
AXGLONG bytes = sizeof(AXGLONG);
int result = ReadFromFile( refNum, &bytes, ¬es_size );
if ( result )
return notes.str();
#ifdef __LITTLE_ENDIAN__
ByteSwapLong( ¬es_size );
#endif
if (notes_size > 0) {
std::vector< unsigned char > charBuffer( notes_size, '\0' );
result = ReadFromFile( refNum, ¬es_size, &charBuffer[0] );
if ( result )
return notes.str();
// Copy characters one by one into title (tedious but safe)
for (std::size_t nc=1; nc<charBuffer.size(); nc+=2) {
notes << char(charBuffer[nc]);
}
}
return notes.str();
}
示例3: main
int main(int argc, char** argv) {
if (argc != 4) {
std::cout << "usage: RSA_decrypt N PRIVATE_KEY CIPHERTEXT\n";
return 0;
}
for (int i = 1; i < 4; i++) {
if (!FileExists(argv[i])) {
std::cout << "File " << argv[i] << " does not exist.\n";
return 0;
}
}
N = ReadFromFile(argv[1]);
d = ReadFromFile(argv[2]);
std::fstream mfile;
mfile.open(argv[3], std::ios::binary | std::ios::in);
mfile >> len;
std::string output;
m.resize(len);
for (int i = 0; i < len; i++) {
mfile >> m[i];
}
for (int i = 0; i < len; i++) {
output += char(Decrypt(m[i]).get_si());
}
std::cout << output;
return 0;
}
示例4: while
// return is only good thru end of level.
// using fgetc() since it auto-converts CRLF pairs
char *ReadTextFile(char *filename) {
FILE *fp;
char *filestring = NULL;
long int i = 0;
struct stat mstat;
if (stat(filename, &mstat) != 0)
return NULL;
while (true) {
fp = fopen(filename, "rb");
if (!fp) break;
i = ReadFromFile(fp, NULL);
filestring = V_Malloc(i, TAG_LEVEL);
if (!filestring)
break;
fseek(fp, 0, SEEK_SET);
ReadFromFile(fp, filestring);
break;
}
if (fp) fclose(fp);
return(filestring); // return new text
}
示例5: ReadFromFile
void RunLog::Load()
{
const string& data1 = ReadFromFile( loopsFile );
const string& data2 = ReadFromFile( logFile );
const string& data3 = ReadFromFile( logFile_Stats );
m_Loops->buildVector( data1 );
m_Log->buildLog( data2 );
m_Log->buildLogStats( data3 );
}
示例6: InitCheck
/*! Constructs a DefaultCatalog with given signature and language and reads
the catalog from disk.
InitCheck() will be B_OK if catalog could be loaded successfully, it will
give an appropriate error-code otherwise.
*/
DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *language,
uint32 fingerprint)
:
HashMapCatalog("", language, fingerprint)
{
// We created the catalog with an invalid signature, but we fix that now.
SetSignature(catalogOwner);
status_t status;
// search for catalog living in sub-folder of app's folder:
node_ref nref;
nref.device = catalogOwner.device;
nref.node = catalogOwner.directory;
BDirectory appDir(&nref);
BString catalogName("locale/");
catalogName << kCatFolder
<< "/" << fSignature
<< "/" << fLanguageName
<< kCatExtension;
BPath catalogPath(&appDir, catalogName.String());
status = ReadFromFile(catalogPath.Path());
if (status != B_OK) {
// search in data folders
directory_which which[] = {
B_USER_DATA_DIRECTORY,
B_COMMON_DATA_DIRECTORY,
B_SYSTEM_DATA_DIRECTORY
};
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
BPath path;
if (find_directory(which[i], &path) == B_OK) {
BString catalogName(path.Path());
catalogName << "/locale/" << kCatFolder
<< "/" << fSignature
<< "/" << fLanguageName
<< kCatExtension;
status = ReadFromFile(catalogName.String());
if (status == B_OK)
break;
}
}
}
if (status != B_OK) {
// give lowest priority to catalog embedded as resource in application
// executable, so they can be overridden easily.
status = ReadFromResource(catalogOwner);
}
fInitCheck = status;
}
示例7: LoadFlat
//======================================
// Load a flat format binary executable
//======================================
void LoadFlat(struct FCB * fHandle)
{
char header[15];
char *location, *temp;
long codelen, datalen, currentPage, size;
int bytesRead, n;
(void) ReadFromFile(fHandle, header, 14);
(void) ReadFromFile(fHandle, (char *) &codelen, 8);
(void) ReadFromFile(fHandle, (char *) &datalen, 8);
// Allocate pages for user code
currentPage = UserCode;
size = codelen;
ClearUserMemory();
while (size > 0)
{
(void) AllocAndCreatePTE(currentPage, currentTask->pid, RW | US | P);
size -= PageSize;
currentPage += PageSize;
}
memcpy((char *) UserCode, (char *) header, 14);
memcpy((char *) UserCode + 14, (char *) &codelen, 8);
memcpy((char *) UserCode + 22, (char *) &datalen, 8);
location = (char *) UserCode + 30;
// Load the user code
(void) ReadFromFile(fHandle, location, codelen - 30);
entrypoint = (void *) UserCode;
// Allocate pages for user data
currentPage = UserData;
size = datalen + sizeof(struct MemStruct);
while (size > 0)
{
(void) AllocAndCreatePTE(currentPage, currentTask->pid, RW | US | P);
size -= PageSize;
currentPage += PageSize;
}
// Load the user data
bytesRead = ReadFromFile(fHandle, (char *) UserData, datalen);
// Zero the rest of the data segment
temp = (char *) (UserData + bytesRead);
while (bytesRead >= PageSize)
bytesRead -= PageSize;
for (n = 0; n < bytesRead; n++)
temp[n] = 0;
currentTask->firstfreemem = UserData + datalen;
}
示例8: CalcWinsAndLosses
// *CalcWinsAndLosses
void CalcWinsAndLosses()
{
double winScore = 0.0, loseScore = 0.0;
ReadFromFile(iScores);//Read In the File
iWins = iScores[0];//Store iScore at pos [0] in iWins
iLosses = iScores[1];//Store iScore at pos [1] in iLosses
iCntGamesPlayed = iScores[2];//Store iScore at pos [2] in iCntGamesPlayed
if (iCntGamesPlayed > 0)//Only Calc %score if games played > 0
{
winScore = (iWins * 100.00) / iCntGamesPlayed + 0.5;//Calc to get persentage of winScore +0.5 To Round up
loseScore = (iLosses * 100.00) / iCntGamesPlayed + 0.5;//Calc to get persentage of loseScore +0.5 To Round up
}
iScores[3] = (int)winScore; //Store winScore in iScores[3]
iScores[4] = (int)loseScore;//Store loseScore in iScores[4]
iPercentWins = iScores[3];//Store iScore at pos [3] in iPercentWins
iPercentLosses = iScores[4];//Store iScore at pos [4] in iPercentLosses
WriteToFile();//Writing to File
}//End CalcWinsAndLosses()
示例9: ReadFromFile
void AuthConfig::RemoveUser()
{
ReadFromFile();
if (m_users.size() == 0)
{
std::cout << "No users to remove." << std::endl << std::endl;
return;
}
PrintUsersList();
std::string userName;
std::cout << "Enter user name to delete:" << std::endl << "> ";
std::getline(std::cin, userName);
auto it = std::find_if(m_users.begin(), m_users.end(), [&](auto user) { return user.Name.compare(userName) == 0; } );
if (it == m_users.end())
{
std::cout << "ERROR: Can't find the user with the entered name." << std::endl << std::endl;
return;
}
std::cout << "Are you sure you want to remove \"" << it->Name << "\" user? [y/n]" << std::endl << "> ";
char key = (char)_getch();
if (key == 'y')
{
m_users.erase(it);
WriteToFile();
std::cout << "User successfully removed." << std::endl << std::endl;
}
else if (key == 'n')
std::cout << "User removal CANCELED." << std::endl << std::endl;
else
std::cout << "Token not recognized. User removal CANCELED." << std::endl << std::endl;
}
示例10: FindFirstFile
void V2Localisation::ReadFromAllFilesInFolder(const std::string& folderPath)
{
// Get all files in the folder.
std::vector<std::string> fileNames;
WIN32_FIND_DATA findData; // the file data
HANDLE findHandle = FindFirstFile((folderPath + "\\*").c_str(), &findData); // the find handle
if (findHandle == INVALID_HANDLE_VALUE)
{
return;
}
do
{
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
fileNames.push_back(findData.cFileName);
}
} while (FindNextFile(findHandle, &findData) != 0);
FindClose(findHandle);
// Read all these files.
for (const auto& fileName : fileNames)
{
ReadFromFile(folderPath + '\\' + fileName);
}
}
示例11: UnwrapKey
int UnwrapKey(const char *pin, int keyid, const char* filename)
{
uint16 sw1sw2;
uint8 *pWrapped;
int len;
int rc = SC_Open(pin, 0);
if (rc < 0)
return rc;
if (!(1 <= keyid && keyid <= 127)) {
printf("keyid (%d) must be between 1 and 127\n", keyid);
return ERR_INVALID;
}
ReadFromFile(filename, pWrapped, len);
if (pWrapped == NULL) {
printf("file '%s' not found\n", filename);
return ERR_INVALID;
}
if (len <= 0) {
free(pWrapped);
printf("file '%s' empty\n", filename);
return ERR_INVALID;
}
/* - SmartCard-HSM: UNWRAP KEY */
rc = SC_ProcessAPDU(
0, 0x80,0x74,keyid,0x93,
pWrapped, len,
NULL, 0,
&sw1sw2);
free(pWrapped);
SC_Close();
if (rc < 0)
return rc;
return sw1sw2;
}
示例12: main
int main(){
MGragh<int> intGragh(10);
ReadFromFile("flight.txt", intGragh);
intGragh.PrintNearest(2, 11);
return 0;
/*for(int i = 0; i < 10; ++i){
intGragh.AddNode(i);
}
intGragh.AddEdge(0, 1);
intGragh.AddEdge(0, 2);
intGragh.AddEdge(0, 3);
intGragh.AddEdge(0, 5);
intGragh.AddEdge(0, 6);
intGragh.AddEdge(1, 2);
intGragh.AddEdge(1, 3);
intGragh.AddEdge(3, 9);
intGragh.AddEdge(3, 4);
intGragh.AddEdge(4, 7);
// intGragh.AddEdge(7, 8);
std::cout << intGragh.GetCurrentNodeCount() << std::endl;
std::cout << intGragh.GetEdgeCount() << std::endl;
std::cout << intGragh.GetMaxNodeCount() << std::endl;
intGragh.PrintNearest(0, 7);
// intGragh.DeepOrder(Print);
intGragh.BroadOrder(Print);*/
}
示例13: GetCurrentProcessId
/**
@param hPrinter Handle to the printer
@return true if loaded the data auccessfully, false if failed to load
*/
bool CCPrintData::LoadProcessData(HANDLE hPrinter)
{
// Get process ID
TCHAR cKeyTime[64], cKeyFile[64];
DWORD dwProcessID = GetCurrentProcessId(), dwTimeKey;
time_t tNow, tKey;
// Clean this data and all the old data
CleanThis();
CleanOldData(hPrinter);
// Check registry for time
_stprintf_s(cKeyTime, _S(cKeyTime), JOBDATA_TIME_KEY, dwProcessID);
if ((dwTimeKey = CCPrintRegistry::GetRegistryDWORD(hPrinter, cKeyTime, 0)) == 0)
// No time, no data
return false;
// Compare times:
tKey = (time_t)dwTimeKey;
tNow = time(NULL);
// Check if time stamp current (up to 5 minutes)
bool bRet = false;
if (difftime(tNow, tKey) < 300)
{
// OK, not too old, read the file name
_stprintf_s(cKeyFile, _S(cKeyFile), JOBDATA_FILE_KEY, dwProcessID);
std::tstring sFilename = CCPrintRegistry::GetRegistryString(hPrinter, cKeyFile, _T(""));
if (!sFilename.empty())
// Found a filename, read the file
bRet = ReadFromFile(sFilename.c_str());
}
return bRet;
}
示例14: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
const int BufferLength = 1024;
char readBuffer[BufferLength] = {0,};
if (false == ReadFromFile("test.json", readBuffer, BufferLength))
return 0;
std::string config_doc = readBuffer;
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse( config_doc, root );
if ( !parsingSuccessful )
{
std::cout << "Failed to parse configuration\n"
<< reader.getFormatedErrorMessages();
return 0;
}
std::string encoding = root.get("encoding", "" ).asString();
std::cout << encoding << std::endl;
const Json::Value plugins = root["plug-ins"];
for ( int index = 0; index < plugins.size(); ++index )
{
std::cout << plugins[index].asString() << std::endl;
}
std::cout << root["indent"].get("length", 0).asInt() << std::endl;
std::cout << root["indent"]["use_space"].asBool() << std::endl;
return 0;
}
示例15: ReadFromFile
void ObjMesh::Init()
{
ReadFromFile(filePath.c_str(), scale_factor);
ComputeNormal();
ApplyTransformation();
ComputeAABB();
}