Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from a file into a combo box

Status
Not open for further replies.

jdeejay

Programmer
Oct 5, 2001
44
US
Hello all,
I am very new to C++ and Visual C++ and am getting very frustrated with this seemingly easy task. How do I fill in a combo box from a text file? I want to just open the file, grab one line of text at a time and add it to the possiblities in a combo box.

Thanks,
 
Hi

Here it is:

char szBuffer[255];

CStdioFile f1;

if( !f1.Open( "c:\\document.txt", CFile::modeRead | CFile::shareDenyNone | CFile::typeText))
{
AfxMessageBox( "Oops");

return;
}

while ( f1.ReadString( szBuffer, 255))
{
szBuffer[strlen(szBuffer)-1] = '\0';

m_Combo.AddString( szBuffer);
}

f1.Close();

The reason of the line
szBuffer[strlen(szBuffer)-1] = '\0';
is to remove the CR/LF at the end of each text line

HTH

Thierry
EMail: Thierry.Marneffe@swing.be
Web Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top