Discussion Locked
0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there a way to type cast an int var to a char[] variable. i need to take an integer variable and use it in part of a file name infile.open(filename) but i need to concatenate it with other char[].
3 replies
by nikki96
I don't know about C++, but it C it's easy.
/* my Int will be set somewhere */
int myInt;
/* set length depending on size of int */
char str[38];
char myFilename[100];
/* further in the program, you want myInt as str */
sprintf(str, "%d", myInt);
/* or say you want it all together as a filename*/
sprintf(str, "%s%d", myFilename, myInt);
If you include the correct library (stdio.h), you can use these functions in C++.
by whitey_brw
Thanks alot!! i have been trying to use typecasting and reinterpert type casting but nothing worked. Your code worked perfectly. thanks again.
by whitey_brw
This question was closed by the author
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending
Discussion Locked
What Makes a Business Website Effective in 2026
2 helpful
10 replies
1 helpful
3 replies
Question
Windows and macOS computers becoming slow or unstable after updates - what should I check first
0 helpful
1 reply
Question Unanswered
Best Way to Make Long WordPress Location Guides Mobile Friendly
0 helpful
0 replies
Discussion
Optimizing WordPress widgets and DOM size
0 helpful
3 replies