int, read from text file
-
i need to be able to read a line from a text file and store what is read in int.
-
i need to be able to read a line from a text file and store what is read in int.
-
And your question is...? /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
Try this,
//File reading---- CFileException ex; //catch exceptions CFile myfile; //Open file myfile.Open("c:/b.txt", CFile::modeRead, &ex); //Get length int z=myfile.GetLength(); //create temp buffer with all data including line breaks char* data=new char[z]; //read data myfile.Read(data,z); //Extract only data, remove line breaks int* value=new int[z/3]; for(int i=0;i
-
i need to be able to read a line from a text file and store what is read in int.
what do you man when you say that you want to store the data in int. do you want to store the number of bytes you read from a file in int'or do you want to store the data in int(in that case -> ???????)? regards, Eli
-
what do you man when you say that you want to store the data in int. do you want to store the number of bytes you read from a file in int'or do you want to store the data in int(in that case -> ???????)? regards, Eli
i want to store the data in int.
-
Try this,
//File reading---- CFileException ex; //catch exceptions CFile myfile; //Open file myfile.Open("c:/b.txt", CFile::modeRead, &ex); //Get length int z=myfile.GetLength(); //create temp buffer with all data including line breaks char* data=new char[z]; //read data myfile.Read(data,z); //Extract only data, remove line breaks int* value=new int[z/3]; for(int i=0;i
what header file to i need for this code?
-
what header file to i need for this code?
-
i need to be able to read a line from a text file and store what is read in int.
Assuming that your file has CR/LF at end of each line. The code below might be easier
CStdioFile myFile("Sample.txt",CFile::modeRead ); CString myBuffer; int myInteger = 0; LPCTSTR pMyBuffer, pMyBufferEnd; myFile.ReadString(myBuffer); while(!myBuffer.IsEmpty()){ pMyBuffer = myBuffer; pMyBufferEnd = pMyBuffer + myBuffer.GetLength(); cout << pMyBuffer << endl; for( pMyBuffer;pMyBuffer <= pMyBufferEnd; pMyBuffer++) { if((*pMyBuffer < '0') ||(*pMyBuffer > '9')) { cout << myInteger << (LPCTSTR) " "; myInteger = 0; } else { myInteger *= 10; myInteger += *pMyBuffer - 48; } } cout << endl; myFile.ReadString(myBuffer); } myFile.Close();
I'll e-mail you a demo. It's a console app (don't worry it supports MFC!) Good luck, happy programming, Alton