Solved

Edit box does not display output

Posted on 1998-11-05
10
278 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
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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now