Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Edit box does not display output

Posted on 1998-11-05
10
Medium Priority
?
286 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 160 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

722 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