Solved

Writing values of a file to a text box in MFC

Posted on 2007-03-18
3
1,136 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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