Click here to Skip to main content
15,915,600 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: static constructors ? Pin
cmk7-Sep-05 2:48
cmk7-Sep-05 2:48 
AnswerRe: static constructors ? Pin
Hugo González Castro26-Nov-11 20:03
professionalHugo González Castro26-Nov-11 20:03 
QuestionBrowse/Open dialog box Pin
bugDanny6-Sep-05 10:14
bugDanny6-Sep-05 10:14 
AnswerRe: Browse/Open dialog box Pin
Ravi Bhavnani6-Sep-05 10:38
professionalRavi Bhavnani6-Sep-05 10:38 
AnswerRe: Browse/Open dialog box Pin
David Crow6-Sep-05 17:10
David Crow6-Sep-05 17:10 
AnswerRe: Browse/Open dialog box Pin
ThatsAlok6-Sep-05 18:59
ThatsAlok6-Sep-05 18:59 
QuestionRead Files Pin
RedDragon2k6-Sep-05 10:11
RedDragon2k6-Sep-05 10:11 
AnswerRe: Read Files Pin
bugDanny6-Sep-05 10:24
bugDanny6-Sep-05 10:24 
I like to use fstream. For example,

#include < fstream.h ><br />
fstream SomeFile;<br />
SomeFile.open(pathToOpen, ios::in | ios::nocreate | ios::noreplace);<br />
if(!SomeFile){<br />
  output = "Error!";<br />
}<br />
SomeFile.getline(TextBuffer, 5000, '\n');


In the example, SomeFile is an fstream object. Open the file with open() (Check MSDN for full stats and flags with this). pathToOpen is a string with the path of the file you want to open. If the string is just a file name it will look in the current path. The ios statements are different flags. This one opens as input (you are reading from the file) and not overwriting or creating the file. An error statement. Then, for your question, the getline(). TextBuffer is a character array the line will be stored at, 5000 is the number of characters to be read, and the last option says to stop at the newline tag if one is read before 5000 characters.

It's easy from there to look at TextBuffer[0] (the first character of the line) or to scan the TextBuffer array until you reach the first word (and make sure it's not prefaced with a ';'. Can comments begin after a line? You can write a loop to look through the TextBuffer until the ';' is reached and replace it with a '\0' (null terminating character). I wouldn't suggest replacing the '\n' in the code with a ';' because, while that might work sometimes, does every line have to have a ';' character? It may then read in several lines.

Hope this helps and is descriptive enough!

Danny
GeneralRe: Read Files Pin
RedDragon2k6-Sep-05 11:02
RedDragon2k6-Sep-05 11:02 
GeneralRe: Read Files Pin
Anonymous6-Sep-05 13:54
Anonymous6-Sep-05 13:54 
GeneralRe: Read Files Pin
bugDanny7-Sep-05 8:26
bugDanny7-Sep-05 8:26 
Answer[Message Deleted] Pin
kakan6-Sep-05 20:39
professionalkakan6-Sep-05 20:39 
AnswerRe: Read Files Pin
kakan6-Sep-05 20:40
professionalkakan6-Sep-05 20:40 
GeneralRe: Read Files Pin
RedDragon2k7-Sep-05 2:49
RedDragon2k7-Sep-05 2:49 
GeneralRe: Read Files Pin
kakan8-Sep-05 0:23
professionalkakan8-Sep-05 0:23 
GeneralRe: Read Files Pin
RedDragon2k8-Sep-05 1:02
RedDragon2k8-Sep-05 1:02 
GeneralRe: Read Files Pin
kakan8-Sep-05 1:44
professionalkakan8-Sep-05 1:44 
QuestionMinimize RAM-usage in MFC? Pin
Gadjuka6-Sep-05 10:06
Gadjuka6-Sep-05 10:06 
AnswerRe: Minimize RAM-usage in MFC? Pin
Blake Miller6-Sep-05 12:30
Blake Miller6-Sep-05 12:30 
GeneralRe: Minimize RAM-usage in MFC? Pin
Gadjuka6-Sep-05 12:46
Gadjuka6-Sep-05 12:46 
AnswerRe: Minimize RAM-usage in MFC? Pin
David Crow6-Sep-05 17:14
David Crow6-Sep-05 17:14 
GeneralRe: Minimize RAM-usage in MFC? Pin
Gadjuka6-Sep-05 23:24
Gadjuka6-Sep-05 23:24 
QuestionHow do I get my IP address ? Pin
Shay Harel6-Sep-05 9:37
Shay Harel6-Sep-05 9:37 
AnswerRe: How do I get my IP address ? Pin
David Crow6-Sep-05 9:50
David Crow6-Sep-05 9:50 
General[Message Deleted] Pin
Shay Harel6-Sep-05 10:35
Shay Harel6-Sep-05 10:35 

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.