dont freak out by length of code! its commented out befiore each block so you dont have 2 read it all..
so anyway! i have a fairly simple question i wld say, all i need is a little guide,
i am trying to write an input stream to write to files, but the file being opened needs to change with each for loop, so i did this - ofstream out;
-
-
-
for (int j=0;j<24;j++){
-
-
/////////int to string
-
string jAsString;
-
stringstream smStrngStrm;
-
smStrngStrm << j;
-
jAsString = smStrngStrm.str();
-
-
-
//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();
-
-
-
out.open(wcstring, ios::out);
-
-
out<<wcstring[0]<<"\n";
-
out<< sizeof(wcstring)<<"\n";
-
-
-
for(int i=0;i!=meshVertices.length();++i) {
-
-
-
-
out //<< pathToGeo
-
<< i << " "
-
<< meshVertices[i].x <<" "
-
<< meshVertices[i].y <<" "
-
<< meshVertices[i].z <<"\n";
-
-
}
-
-
-
out.close();
-
-
}
but it doesnt seem to be opening the file with the string name wcstring, and when i try to print it out, i mean the variable, i get some hexadecimal stuff, does anyone have a clue???? thanks
1 4274
dont freak out by length of code! its commented out befiore each block so you dont have 2 read it all..
so anyway! i have a fairly simple question i wld say, all i need is a little guide,
i am trying to write an input stream to write to files, but the file being opened needs to change with each for loop, so i did this
ofstream out;
for (int j=0;j<24;j++){
/////////int to string
string jAsString;
stringstream smStrngStrm;
smStrngStrm << j;
jAsString = smStrngStrm.str();
//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();
out.open(wcstring, ios::out);
out<<wcstring[0]<<"\n";
out<< sizeof(wcstring)<<"\n";
for(int i=0;i!=meshVertices.length();++i) {
out //<< pathToGeo
<< i << " "
<< meshVertices[i].x <<" "
<< meshVertices[i].y <<" "
<< meshVertices[i].z <<"\n";
}
out.close();
}
but it doesnt seem to be opening the file with the string name wcstring, and when i try to print it out, i mean the variable, i get some hexadecimal stuff, does anyone have a clue???? thanks
I don't think you need to do all of that code to open the file: -
string filePath = "geo";
-
filePath += jAsString;
-
filePath += ".cache";
-
-
out.open(filePath.c_str(), ios::out);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ma740988 |
last post by:
There's no way to use the STL algorithm copy to print an outfile
(essentially an ofstream)? So now:
int main()
{
std::ifstream InFile( "exercise15.txt");
std::ofstream ToFile( "NewFile.txt"...
|
by: phoenix |
last post by:
How can i read a numbers from file.. I created this file like this:
int dane, i;
std::ofstream plik_z;
plik_z.open(nazwa, std::ios::out | std::ios::trunc | std::ios::binary);
for (i = 0; i <...
|
by: jois.de.vivre |
last post by:
Hi,
I'm trying to write to an ofstream, and for some reason it fails. I
know I can check it with fail() or bad(), but it gives me no useful
information as to why it fails. Are there any C++...
|
by: keweiming |
last post by:
I have a project which needs to open hundreds to thousands of files for
writing. The following is a simplified test program I wrote to see if I
can use a map<string, ofstream> object to keep the...
|
by: davihigh |
last post by:
My Friends:
I am using std::ofstream (as well as ifstream), I hope that when i
wrote in some std::string(...) with locale, ofstream can convert to
UTF-8 encoding and save file to disk. So does...
|
by: shyam |
last post by:
HI
I have a logging application wherin I create a ofstream object say,
ofstream logger;
by doing this
logger.open(/* some path*/,ios_base:app);
|
by: rEvolution27 |
last post by:
I'm a c++ newbie here, trying out some stuff and when I try to compile
this:
void create() {
char name;
cout << "Creating a new timetable /n Please type a name for this
timetable";
cin >name;...
|
by: askalottaqs |
last post by:
i want to open an ofstream but with a variable, i keep being told that i cant convert from string to const wchar_t * , has anyone ever faced this problem?
i tried all types of conversions, but i...
|
by: Ioannis Vranos |
last post by:
The following code does not work as expected:
#include <wchar.h>
#include <locale.h>
#include <stdio.h>
#include <stddef.h>
int main()
{
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |