im a noob with all the c++ stuff, working on the maya API, stuff have been flowing pretty smoothly, but my main problem all the time is the type conversions! i cant believe its that complicated, is there like an easy way that i dont know about? i need to do a conversion from a string to a wchar_t, and its not working at all, and all tutorials are kind of advanced and assume quite a previous knowledge of c++, so could anyone simplify stuff for me??
thanks alot
3 1501
A string has char elements. You need to convert those to wchar_t. If you are using Windows, you can call mbstowcs().
If effect you are converting a string to a wstring.
Type conversions are not complicated. They are simple an orderly transformation of one to to another. And yes, you may need some knowledge of C++ in order to do this. I'm sure Google and MSDN are loaded wirth info.
A type cast is entirely different. A cast is an assertion by you that an thing of type A is really a thing of type B. It is an official way of lying to the compiler.
Type conversions are to be embraced and type casts are to be shunned.
i didnt come here before having looked around a LOT, and after, i managed to convert and it does compile, but when i print the results out (after conversion) thru the usual cout<< i get some kind of hexadecimal printing everytime "0103F544"
thanks again
let me cut it short, im trying to open files over a for loopwith each loop a new file opens, adds wwatever i want and closes, im doing this so far -
-
for (int j=0;j<24;j++){
-
-
/////////int to string
-
string jAsString;
-
stringstream smStrngStrm;
-
smStrngStrm << j;
-
jAsString = smStrngStrm.str();
-
-
/////////////// file name
-
-
//file path in string format, to be cnverted to wchar_t
-
string filePath = "geo";
-
filePath += jAsString;
-
filePath += ".cache";
-
-
-
-
-
// First convert to a char*
-
string cstring = filePath;
-
const size_t newsize = 100;
-
char pathChar[newsize];
-
strcpy_s(pathChar, cstring.c_str());
-
strcat_s(pathChar, " (char *)");
-
-
// Then convert to a wchar_t*
-
size_t origsize = strlen(cstring.c_str()) + 1;
-
size_t convertedChars = 0;
-
wchar_t wcstring[newsize];
-
mbstowcs_s(&convertedChars, wcstring, origsize, cstring.c_str(), _TRUNCATE);
-
wcscat_s(wcstring, L" (wchar_t *)");
-
-
const char *pathAsChar = filePath.c_str();
-
-
-
-
-
-
fopen(filePath,"w");
-
-
//print verts to file
-
-
// the problem is right here! the wcstring doesnt seem to be right, and // //therefore doesnt open the file to write...
-
-
out.open(wcstring, ios::out);
-
-
out<<wcstring[0]<<"\n";
-
-
-
-
-
-
for(int i=0;i!=meshVertices.length();++i) {
-
-
// code here is maya api, works well on a single file
-
out //<< pathToGeo
-
<< i << " "
-
<< meshVertices[i].x <<" "
-
<< meshVertices[i].y <<" "
-
<< meshVertices[i].z <<"\n";
-
-
//cout<< meshVertices[i].x ;
-
-
}
-
-
-
// out.close();
-
-
fclose(pFile);
-
-
}
-
-
-
}
anyone????
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Terje Slettebø |
last post by:
Hi.
I'm new here, and sorry if this has been discussed before; I didn't find it
searching the PHP groups. (I've also read recommendations to cross-post to
the other PHP groups, but if that is...
|
by: Rade |
last post by:
Following a discussion on another thread here... I have tried to understand
what is actually standardized in C++ regarding the representing of integers
(signed and unsigned) and their conversions....
|
by: buda |
last post by:
Let me see if I got this :)
1. I know the rules for type conversions in arithmetic expressions
2. I know that an implicit type conversion is done at assignment, so
float x = 1.23;
int t = (int)...
|
by: jacob navia |
last post by:
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are. I came up with the following text.
Please can you comment?
Did I miss something?
Is...
|
by: Sam Sungshik Kong |
last post by:
Hello!
I studied C# a little bit and am trying to compare it with VB.Net.
There's 'Option Strict' in VB.Net.
I thought that if I turn it on, it is as strict as C# when checking types.
See...
|
by: mra |
last post by:
I want to cast an object that I have created from a typename to the
corresponding type. Can anycone tell me how to do this?
Example:
//Here, Create the object of type "MyClass"
object...
|
by: Enekajmer |
last post by:
Hi,
1 int main()
2 {
3 float a = 17.5;
4 printf("%d\n", a);
5 printf("%d\n", *(int *)&a);
6 return 0;
7 }
|
by: Martin Jørgensen |
last post by:
Hi,
Short question:
Any particular reason for why I'm getting a warning here:
(cast from function call of type int to non-matching type double)
xdouble = (double)rand()/(double)RAND_MAX;
|
by: Akaketwa |
last post by:
guys help me on this rather nubish question.I have created a new data
type in java and i also want to create a new data type object in db2
that will store the money data object. The money...
|
by: neha_chhatre |
last post by:
which is the best format specifier(data type) if i have to work with
decimal number.
also please tell me the syntax for truncating a decimal number
please reply as soon as possible
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |