Solved

Edit box does not display output

Posted on 1998-11-05
10
284 Views
Last Modified: 2007-10-18
I have an Edit box which is part of a dialog box.
What I am trying to achieve is to read some data from a file and then to display some of the contents back to the edit boxes I have. I have no trouble when displaying numbers in other edit boxes. But when trying to display strings, then it stays blanks.

In the example below, the variable attached to the Edit box is a CString. Please find below the code used:

string CashOrSwap;
fstream      InpFil("C:\\Tads\\DPRM files\\MDRYieldCurvesCcy.HKD.01",ios::in);
string      CurLin;
getline(InpFil,CurLin,'\n');
InpFil >> FirstInt >> MOrYLetter >> CashOrSwap >> From >> Hyphen >> To;
m_HkdInstru1 = CashOrSwap.c_str();
//m_HkdInstru1 is the CString variable attached to the edit box

If I just write m_HkdInstru = "fwebfweub";
then the garbage "fwebfweub" will be displayed correctly.

I am not sure what is happening !
So can anyone provide me with a solution to display my string variable in my CString edit box ?

Rgds,
A.
0
Comment
Question by:decornez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Expert Comment

by:kashif063098
ID: 1177051
Write UpdateData(FALSE); after m_HkdInstru1 = CashOrSwap.c_str();
i think it will solve your problem.


0
 
LVL 5

Expert Comment

by:yonat
ID: 1177052
If you set a break point at the line
    m_HkdInstru1 = CashOrSwap.c_str();
Does CashOrSwap has some meaningful content? If it does, does m_HkdInstru1 has a meaningful content after this line is executed?
0
 

Author Comment

by:decornez
ID: 1177053
kashif,

Thanks for your proposed answer, but it is not the reason.
I already have this line of code in my program.

Rgds,
A.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Norbert
ID: 1177054
Are you sure that you have
UpdateData(FALSE) ?
uf you only call UpdateData()
it will operate with TRUE what means that the data from the edit box is written back to the member variable.
0
 

Author Comment

by:decornez
ID: 1177055
Norbert,

Yes I am sure.
It is also located after all this code.


Rgds,
Arnaud.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1177056
decornez, did you see my previous comment? Here it is again:

If you set a break point at the line
    m_HkdInstru1 = CashOrSwap.c_str();
Does CashOrSwap has some meaningful content? If it does, does m_HkdInstru1 has a meaningful content after this line is executed?
0
 

Author Comment

by:decornez
ID: 1177057
Yonat,

I am afraid I am rather unfamiliar with the MS VC++ debugger. Give me a bit of time to sort it out as at the moment when I try to put a breakpoint on that line it does not seem to accept. I will hopefully figure it out within a few minutes/hours and let you know what the outcome is.

A.
0
 

Author Comment

by:decornez
ID: 1177058
Yonat,

I have sorted out the debugger.
For your info, here is what my code looks like (you will recognize your .c_str() ) :

/////////////////////////////////////////////////////////////////////////////////
while(!InpFil.eof()) // While not at the end of the file.
       {
          InpFil >> FirstInt >> MOrYLetter >> CashOrSwap >> From >> Hyphen >> To;
          getline(InpFil,CurLin); // Get current line.
       }
      m_HkdBid1 = From;
      m_HkdInstru1 = CashOrSwap.c_str();
/////////////////////////////////////////////////////////////////////////////////

It looks like the while loop tries to read one more line than it should.
I am not sure why, maybe an eof flag problem with that file.
Anyway, since for testing I had put "m_HkdInstru1 = CashOrSwap.c_str(); " outside the while loop, it was trying to read the last available CashOrSwap produced by that loop.
But since the loop is reading one extra "rubbish" line the content of CashOrSwap was blanked.
When I put "m_HkdInstru1 = CashOrSwap.c_str(); " inside the loop, m_HkdInstru1 is being updated properly, so the c_str() bit works fine :o)
So I think that to sort my problem I will use the while loop to first count the number of lines I want to read, and then use a For Next with appropriate number of steps to update my controls.

I will try it and will keep you posted.
Yonat since you got me on the right track by pushing me to use the debugger I will give you the points.
Just put an answer and they are yours.

By the way, the reason why I was having some troubles with the debugger is that I was in Release mode ! Ooooops

Thanks,
A.
0
 
LVL 5

Accepted Solution

by:
yonat earned 40 total points
ID: 1177059
Seems you stumbled on the infamous getline bug! See http://www.dinkumware.com/vc_fixes.html for a fix.
0
 

Author Comment

by:decornez
ID: 1177060
I will check it out.

Thanks,
A.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question