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 4293
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(pathCh ar, cstring.c_str() );
strcat_s(pathCh ar, " (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(&con vertedChars, wcstring, origsize, cstring.c_str() , _TRUNCATE);
wcscat_s(wcstri ng, L" (wchar_t *)");
const char *pathAsChar = filePath.c_str( );
out.open(wcstri ng, ios::out);
out<<wcstring[0]<<"\n";
out<< sizeof(wcstring )<<"\n";
for(int i=0;i!=meshVert ices.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" );
////////////////////////////
// Alternative 1
|
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 < 15; i++) plik_z << dane;
plik_z.close();
Is it any way to read from this file all numbers ?.. If so - how can i do
|
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++ functions that do
this or is there any way I can check manually?
Thanks,
Prashant
|
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 list of ofstreams. I
need to have them open simultaneously for writing -- I have millions of
rows of data to write to them so opening and closing all the time will
be unacceptable in efficiency.
The following program compiles but failed to run....
|
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 ifstream.
Something I found shows that, I need to have a proper codecvt to set
it. I need more information, maybe a small piece of code sample. Thank
you!
| |
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;
ofstream editFile;
editFile.open (name, ios::out | ios::app);
|
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 figured there must be an easier way out,
thanks
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |