Solved

Writing values of a file to a text box in MFC

Posted on 2007-03-18
3
1,139 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
[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
  • 2
3 Comments
 
LVL 12

Expert Comment

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

Author Comment

by:indacrypt
ID: 18747520
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
ID: 18749888
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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