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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BcB help

Status
Not open for further replies.

larcrik

Programmer
Aug 29, 2007
11
DE
Hello. I'm not quite familiar with the BCB so pls help me with this.
I wrote this code:
-----------------------
ifstream in("D:\\config96.h");
ofstream out("D:\\raspuns.h");
string line;
while(getline(in,line))
if(line.find("CONFMODE")!= -1){
for(int i=0;i<7;i++) line=0;
out<<line<<endl;
-----------------------------
it works..if i write it into a Console Wizard. But I whant to use it into a project with a form. What I actually whant is to write the lines not into another file but into a RichEditBox.
I don't know how to do that(if it is even possible).
Do I have to create a new class? or it is enought to create a method into Main?
:D...I'm realy confused..
ok.any advice?...
thanks.
}
 
This is off the top of my head so take it for what it's worth. Try this:
Code:
ifstream in("D:\\config96.h");
string line;
namespace has been set
while(getline(in,line))
{
    if(line.find("CONFMODE")!= -1)
    {
        for(int i=0;i<7;i++) line[i]=0;
        // So far, all I've done is copy your code
        // This is where the "trick" is
        AnsiString LineStr = line.c_str();
        MyRichEdit->Lines->Add(LineStr);
    }
}

I couldn't see where your closing braces were so I guessed. When I use standard strings, I always put them into AnsiStrings before moving the AnsiStrings into Borland's components like TMemoEdit or TRichEdit.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Opps! I just noticed that an extra line had crept in. Remove the line that says, "namespace has been set." I was going to add a comment here but decided not to. Somehow I missed this line.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Thanks 2ffat.
I tried, but I don't know what I'm missing.The RichEdit box extends, like something is being written in it. But the text is not visible. Can you pls take a look?
thank you.
 
Glad I could help.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
So do you have any idea how can I make the code work with the for included? I still need that line:D..
I need to get rid of the first word in every line. I want only the last part of the sentence(line).
(with that done my project is completed).
So if you can pls help, if not thanks anyway. You've been a big help.
 
I do this quite frequently using streams. You say you only want the last part of the line. At this point I need to know more about the line before I can answer.

Q: Is the line delimited? Is so, how (with commas, spaces, tabs, etc.)?

Q: If the line is not delimited, how can we tell how much of the line you need (number of characters, etc.)?

Q: What is the purpose of the for loop in the original code. I can make a guess but I would rather have a solid answer.

Depending on how you answer these questions will determine how we proceed. We can use stream functions, string functions, or AnsiString functions.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Well it's the same word in every line, " #define ", at the begining of the lines. That's why I tried to overwrite those 7 characters with 0, that's the loop for.
If it can't work within the code, I guess I could have another RichEdit box and cut the first word (delimited by a space. all the words in the file are delimited by a space).
But I don't know how to do that either.
 
OK, lets try this then:
Code:
ifstream in("D:\\config96.h");
string line;
namespace has been set
while(getline(in,line))
{
    if(line.find("CONFMODE")!= -1)
    {
        for(int i=0;i<7;i++) line[i]=0;
        // So far, all I've done is copy your code
        // This is where the "trick" is
        AnsiString LineStr = line.c_str();

        // I'll break this into parts for review
        // You could easily combine these lines
        // Or you could do this via std::strings or streams
        int LineLenInt = LineStr.Length(); // length of line
        int StartInt = 7;
        AnsiString NewLineStr = LineStr.SubString(StartInt, LineLenInt; // Get only the end of the line
        MyRichEdit->Lines->Add(LineStr); // ta-da!
    }
}



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Opps! MyRichEdit->Lines->Add(LineStr); should be
Code:
MyRichEdit->Lines->Add(NewLineStr);

Again, I going from memory here so play with it a little.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Thank you very much 2ffat. You've been a real help.The code works just fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top