The STL string class has a c_str() method that will give you such an object.
With vector<char> you would probably use &v[0].
-----Original Message-----
From: Noorez Kassam [mailto:lor...@ho...]
Sent: Monday, July 11, 2005 3:27 PM
To: Mat...@Ve...
Subject: RE: [Dev-C++] Reading from text file
I was using these two functions to put text into the edit control:
SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_SETSEL, (WPARAM)nLength,
(LPARAM)nLength );
SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_REPLACESEL, (WPARAM)FALSE,
(LPARAM)inLine );
inLine was of type char*, the argument that the function will accept but how
can I do it with the vector<char> or string type?
>From: Mat...@Ve...
>To: lor...@ho...
>Subject: RE: [Dev-C++] Reading from text file
>Date: Mon, 11 Jul 2005 10:02:08 -0700
>
>Do not used fixed size buffers such as inLine is in your program or your
>code will have a buffer overflow.
>
>This is why C++ gives you vector<char> and string classes. Use these
>instead.
>
>-----Original Message-----
>From: dev...@li...
>[mailto:dev...@li...]On Behalf Of Noorez
>Kassam
>Sent: Friday, July 08, 2005 1:38 PM
>To: dev...@li...
>Subject: [Dev-C++] Reading from text file
>
>
>I am having trouble with reading from a text file in my program. For
>testing, I used notepad and typed and let word-wrap put text on the next
>line. I typed a lot into this file. I then used my program to try and open
>it but it froze. If I use the enter key to put in the newline then my
>program works. Whats wrong with it?
>
>#include "SML.h"
>
>// Function called from WindowProcedure to open text
>void OpenText(HWND main, HWND hEdit)
>{
> ifstream openTextFile; // Handle to file
>
> // Filter files visible in the open dialog box
> char* filter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
>
> char* inLine = new char[900];
>
> int nLength;
>
> // Init the properties of the open dialog box
> getOFNproperties(main, &dialogProperties, currentFileName, filter);
>
> // Show the dialog and get the information
> if( !GetOpenFileName(&dialogProperties) )
> {
> return; // Return if user cancels
> }
>
> openTextFile.open(currentFileName);
>
> SetDlgItemText(main, IDC_MAIN_EDIT, ""); // Clear the edit control
>
> int cntr = 1;
>
> // Loop unitl the end of file is reached
> while( !openTextFile.eof() )
> {
> nLength = GetWindowTextLength(GetDlgItem(main, IDC_MAIN_EDIT));
> openTextFile.getline(inLine,9000);
>
> // A new line must have a "\r\n" so test for both
> if( inLine[ strlen(inLine) -1 ] != '\r' )
> {
> strcat(inLine,"\r");
> }
> if( inLine[ strlen(inLine) -1] != '\n' )
> {
> strcat(inLine,"\n");
> }
>
> // And the message onto the edit control
> SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_SETSEL,
>(WPARAM)nLength,
> (LPARAM)nLength );
>
> SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_REPLACESEL,
>(WPARAM)FALSE,
> (LPARAM)inLine );
> delete inLine;
> inLine = new char[900];
> }
>
> untitled = false;
> edited = false;
> return;
>}
>
>_________________________________________________________________
>Designer Mail isn't just fun to send, it's fun to receive. Use special
>stationery, fonts and colors.
>http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=ht
t
>p://hotmail.com/enca&HL=Market_MSNIS_Taglines
> Start enjoying all the benefits of MSN(r) Premium right now and get the
>first two months FREE*.
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by the 'Do More With Dual!' webinar
>happening
>July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
>core and dual graphics technology at this free one hour event hosted by HP,
>AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>___________________________________________________________________
>The information contained in this message and any attachment may be
>proprietary, confidential, and privileged or subject to the work
>product doctrine and thus protected from disclosure. If the reader
>of this message is not the intended recipient, or an employee or
>agent responsible for delivering this message to the intended
>recipient, you are hereby notified that any dissemination,
>distribution or copying of this communication is strictly prohibited.
>If you have received this communication in error, please notify me
>immediately by replying to this message and deleting it and all
>copies and backups thereof. Thank you.
>
_________________________________________________________________
Scan and help eliminate destructive viruses from your inbound and outbound
e-mail and attachments.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=htt
p://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN(r) Premium right now and get the
first two months FREE*.
|