Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have another problem with the open button, I have two errors at form.caption:

error C2664: 'void ATL::CStringT<basetype,stringtraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [12]' to 'const wchar_t *'

caption.Format("Student: %s", name);


error C2664: 'void ATL::CStringT<basetype,stringtraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'

this->m_StudentName.Format("%s", name);


Here is the full code, as I said, I want to open a saved file (binary):

void CROSH1Dlg::OnBnClickedOpen()
{
	UpdateData();
 
	CStudentGrade StdGrades;
	CFile fleGrades;
	
	//TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||" );
	//CFileDialog dlgFile(FALSE,_T(".dnt"), strFilename, 0, strFilter);
	
	TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||");
	CFileDialog dlgFile (TRUE,_T(".dnt"), NULL, 0, strFilter);
 
	if( dlgFile.DoModal() == IDOK )
	{
		// Open a record in binary format
		ifstream stmGrades(dlgFile.GetFileName(), ios::binary);
		stmGrades.read((char *)&StdGrades, sizeof(StdGrades));
 
		// Change the caption of the dialog box to reflect the current grade
		char name[40];
		//strcpy(name, StdGrades.StudentName);
		 StdGrades.StudentName=name;
		CString caption;
		caption.Format("Student: %s", name);
		this->SetWindowText(caption);
 
		// Display the record in the dialog box
		this->m_StudentName.Format("%s", name);
		this->m_SchoolYear1 = StdGrades.SchoolYear1;
		this->m_SchoolYear2 = StdGrades.SchoolYear2;
		this->m_English     = StdGrades.English;
		this->m_History     = StdGrades.History;
		this->m_Economics   = StdGrades.Economics;
		this->m_2ndLanguage = StdGrades.Language2;
		this->m_Geography   = StdGrades.Geography;
		this->m_Arts        = StdGrades.Arts;
		this->m_Math        = StdGrades.Math;
		this->m_Science     = StdGrades.Science;
		this->m_PhysEduc    = StdGrades.PhysEduc;
		this->m_Total       = StdGrades.Total;
		this->m_Average     = StdGrades.Average;
	}
 
	UpdateData(FALSE);
}
Posted
Comments
Spawn705 18-Apr-11 13:04pm    
I have another error at the strcpy(name, StdGrades.StudentName):
error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *'

You have a Unicode build. So you need to prefix L to the string literals. Example:

L"hello"

Or if you want to target Unicode and Ansi, use _T("hello")

C++
caption.Format(L"Student: %s", name);
 
Share this answer
 
Use the _T macro for the strings.

caption.Format(_T("Student: %s"), name);
 
Share this answer
 
For you next problem:
Please use the following code:
strcpy(name, StdGrades.StudentName.GetString()):


Hope this might help you!!! :)
 
Share this answer
 
Comments
Spawn705 19-Apr-11 11:19am    
error C2664: 'strcpy' : cannot convert parameter 2 from 'const wchar_t *' to 'const char *'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900