Peter Chan
asked on
Problem to the line
Hi,
How to correct the last line below?
How to correct the last line below?
struct nameval
{
char fld_nm[100];
wchar_t fld_nm_t[100];
int fld_len;
int fld_val;
};
nameval binrec;
...
int main()
{
std::vector<nameval> records;
int cnt;
for (cnt=0;cnt<20000;cnt++)
{
nameval val={0};
...
val.fld_nm_t=val.fld_nm;
...
due to this error?1> stdafx.cpp
1> pro_b.cpp
1>c:\pro_b\pro_b\pro_b.cpp(64): error C2440: '=' : cannot convert from 'char [100]' to 'wchar_t [100]'
1> There is no context in which this conversion is possible
ASKER
How to correct the last line below
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <string>
#include <ctype.h>
#include <time.h>
#include <process.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
struct nameval
{
char fld_nm[100];
wchar_t fld_nm_t[100];
int fld_len;
int fld_val;
};
nameval binrec;
int main()
{
std::vector<nameval> records;
int cnt;
for (cnt=0;cnt<20000;cnt++)
{
nameval val={0};
int j;
for (j=0;j<20;j++)
{
val.fld_nm[j] += (char)(rand () % 58 + 64);
}
wchar_t wbuf[100]={0};
mbstowcs(wbuf,val.fld_nm,_countof(val.fld_nm));
val.fld_nm_t=wbuf;
...
due to this error?1>------ Rebuild All started: Project: pro_b, Configuration: Debug Win32 ------
1> stdafx.cpp
1> pro_b.cpp
1>c:\pro_b\pro_b\pro_b.cpp(64): warning C4996: 'mbstowcs': This function or variable may be unsafe. Consider using mbstowcs_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h(498) : see declaration of 'mbstowcs'
1>c:\pro_b\pro_b\pro_b.cpp(65): error C2106: '=' : left operand must be l-value
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can I have more details to use memcpy? thanks
What about the example given isn't clear - it involves one line of code.
ASKER
I am not sure about its syntax. sorry
Is this what you need?
wmemcpy(val.fld_nm_t, wbuf, 100);
wmemcpy(val.fld_nm_t, wbuf, 100);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See:
http://msdn.microsoft.com/en-us/library/8tdk45ff.aspx
for the wctomb function which will do this for you. There is example code there.