Click here to Skip to main content
15,923,273 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Programming in C++, Help Me!!! Pin
George L. Jackson21-Jun-07 1:36
George L. Jackson21-Jun-07 1:36 
GeneralRe: Programming in C++, Help Me!!! Pin
DevMentor.org11-Jul-07 19:38
DevMentor.org11-Jul-07 19:38 
GeneralRe: Programming in C++, Help Me!!! Pin
DevMentor.org11-Jul-07 19:44
DevMentor.org11-Jul-07 19:44 
GeneralRe: Programming in C++, Help Me!!! Pin
George L. Jackson17-Jul-07 13:41
George L. Jackson17-Jul-07 13:41 
QuestionHTMLDocument::Write() with iframe Pin
daviddddd18-Jun-07 5:10
daviddddd18-Jun-07 5:10 
AnswerRe: HTMLDocument::Write() with iframe Pin
daviddddd18-Jun-07 6:07
daviddddd18-Jun-07 6:07 
Questionreading string from a file without mfc support in vc++ Pin
rindam15-Jun-07 19:23
rindam15-Jun-07 19:23 
AnswerRe: reading string from a file without mfc support in vc++ Pin
Cheeran Santhosh17-Jun-07 1:04
Cheeran Santhosh17-Jun-07 1:04 
Here are a couple of problems with this code

1) GetBuffer() memory has to be released with ReleaseBuffer

2) fwrite( strTitleCurrentDate, sizeof(TCHAR), strTitle.GetLength()/** sizeof( TCHAR )*/, fp );

How do you decide to write strTitleCurrentDate to the length of strTitle, they are not related ... Correction strTitleCurrentDate.GetLength()

3) Here is even more ambiguous code

CString strTitle1;
newBuffer=strTitle1.GetBuffer(strTitle1.GetLength()* sizeof( TCHAR ));

What is the size of allocation ? strTitle1 is a zero length string! Zero and you decide to read

fread( newBuffer, sizeof(char), 100/** sizeof( TCHAR )*/, fp );

100 bytes to this buffer.

Shouldn't this be

fread( newBuffer, sizeof(TCHAR), strTitle1.GetLength(), fp );

if your allocation was right ?

However it should be just

TCHAR myFileBuffer[1024];
fread( myFileBuffer, sizeof(TCHAR), 1024, fp );

why use GetBuffer ?

Remember when dealing with a char pointer, when you cross what you have allocated, you are writing in to other non allocated memory. You have to always allocate for the string terminator. Any such memory overwrite results in crash, usually later in the code.

How to use google

type "how to read a text file line by line" and see the google results, open the second link and it has the following piece of code for a similar task. Please modify this code to get your stuff done. So another advice, try to use google much more with different search strings representing the same question.

#include <iostream>
#include <fstream>
#include <strstream>

using namespace std;

int main()
{
char buffer1[2048];
char buffer2[2048];
istrstream ostr1(buffer1, 2048);
istrstream ostr2(buffer2, 2048);
int values1[100];
int values2[100];
int c=0;

ifstream fin("data.txt");

fin.getline(buffer1, 2048);
fin.getline(buffer2, 2048);

while (ostr1 >> values1[c])
{
ostr2 >> values2[c++];
}

for (int i=0;i<c;i++)
{
="" cout="" <<="" values1[i]="" ":"="" values2[i]="" endl;
="" }


good="" luck,
santhosh




=""

<div="" class="ForumSig">Live and let live Smile | :)
Questiontools for documenting atl component Pin
Radha Krishna Reddy14-Jun-07 2:28
Radha Krishna Reddy14-Jun-07 2:28 
AnswerRe: tools for documenting atl component Pin
Kevin McFarlane18-Jun-07 23:51
Kevin McFarlane18-Jun-07 23:51 
QuestionImplement address book Pin
Radha Krishna Reddy13-Jun-07 22:55
Radha Krishna Reddy13-Jun-07 22:55 
QuestionConnection points for Chat server using ATL/COM Pin
Raj Prathap12-Jun-07 0:23
Raj Prathap12-Jun-07 0:23 
AnswerRe: Connection points for Chat server using ATL/COM Pin
Roger Stoltz12-Jun-07 21:31
Roger Stoltz12-Jun-07 21:31 
GeneralWTL 8.0 Released! Pin
Rob Caldecott11-Jun-07 12:43
Rob Caldecott11-Jun-07 12:43 
GeneralRe: WTL 8.0 Released! Pin
Stuart Dootson11-Jun-07 21:10
professionalStuart Dootson11-Jun-07 21:10 
GeneralRe: WTL 8.0 Released! Pin
DevMentor.org11-Jul-07 23:59
DevMentor.org11-Jul-07 23:59 
QuestionTool Tip on List Control Pin
Abhijeet Rajput10-Jun-07 23:33
Abhijeet Rajput10-Jun-07 23:33 
QuestionCommunication of CCheckListViewCtrl with parent CMainFrame Pin
Vlad09-Jun-07 7:53
Vlad09-Jun-07 7:53 
AnswerRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Stuart Dootson9-Jun-07 14:39
professionalStuart Dootson9-Jun-07 14:39 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Vlad010-Jun-07 7:37
Vlad010-Jun-07 7:37 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Stuart Dootson10-Jun-07 7:55
professionalStuart Dootson10-Jun-07 7:55 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Vlad010-Jun-07 8:11
Vlad010-Jun-07 8:11 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Stuart Dootson10-Jun-07 8:27
professionalStuart Dootson10-Jun-07 8:27 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Vlad011-Jun-07 8:20
Vlad011-Jun-07 8:20 
GeneralRe: Communication of CCheckListViewCtrl with parent CMainFrame Pin
Stuart Dootson11-Jun-07 8:40
professionalStuart Dootson11-Jun-07 8:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.