Solved

Writing values of a file to a text box in MFC

Posted on 2007-03-18
3
1,130 Views
Last Modified: 2013-11-26
Hi,
Im trying to write to an edit control window in and MFC project. Im reading values from a file into a string, and im using IDC_OUT.SetWindowText(stringtoprint). This gives me an error"CWnd::SetWindowTextA' : cannot convert parameter 1 from 'std::string' to 'LPCTSTR'".

How else can I write to the text box?Thanks!
-D
0
Comment
Question by:indacrypt
  • 2
3 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
Use explicit std::string method:
IDC_OUT.SetWindowText(stringtoprint.c_str()).
0
 

Author Comment

by:indacrypt
Comment Utility
Hi thanks for your reply. The following code that I have prints only the last line of the foutput file into the edit control window. How do i fix this?
THanks!
___
      fstream foutput;

      foutput.open("resultsfile.txt");
        if (foutput.is_open())
        {
            while (! foutput.eof() )
            {
                  getline (foutput,output);
                  IDC_OUT.SetWindowText(output.c_str());
            }
            foutput.close();
      }
___
0
 
LVL 12

Accepted Solution

by:
migel earned 125 total points
Comment Utility
Hello
Use ReplaceSel CEdit method
example
{
    fstream foutput;

      foutput.open("resultsfile.txt");
        if (foutput.is_open())
        {
            while (! foutput.eof() )
            {
                  int len = IDC_OUT.GetWindowTextLength();
                  IDC_OUT.SetSel(len, len);
                  getline (foutput,output);
                  IDC_OUT.ReplaceSel(output.c_str());
            }
            foutput.close();
      }}
0

Featured Post

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.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

772 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

11 Experts available now in Live!

Get 1:1 Help Now