?
Solved

Writing values of a file to a text box in MFC

Posted on 2007-03-18
3
Medium Priority
?
1,141 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 375 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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