All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
You can change the separator quite easily: It is defined as a local String variable right at the top of DataToFile().
You can read in the data file to a String array using File::ReadAllLines(), dissect the lines read from the file into the individual fields using String::Split() and use the Parse() methods of DateTime and double to convert the string representation of the fields to the respective types.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
I am nuts about c ++
A code written for export as a csv from a program
How to read code from csv file (Date; TimeSeries) and transfer code to a program???
''There may also be a second csv file in the same format.Reading and writing csv''' picture upload
Last edited by mimtek; April 30th, 2017 at 07:38 AM.
I just pointed you to the relevant pieces of the .NET framework, including links to their documentation on MSDN, in my previous post. These also contain code samples demonstrating their use. There are only code samples in C# and VB .NET, but for one who is able to read C++/CLI code, the C# samples shouldn't be too hard to understand. (Ok, links to docs on the Parse() methods were missing. Here they are: DateTime::Parse(), double::Parse()) You just have to put these pieces together.
Sorry, I'm not going to write this simple piece of code for you. Give it a try yourself, and if you'll encounter difficulties, you're welcome to post a (more specific) question here.
As to reading another CSV file: what's the problem with this? Once you have the code to read the first file, you can use the same code for the other file as well; just change the file name. (Or better, of course, make a method out of your reading code and pass the file name as a parameter.)
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Unfortunately, the error code in your screenshot is unreadable due to compression loss. It may or may not be a useful hint for discovering the reason of the fault. However, the error message refers to automation, and since your code doesn't contain anything related to automation, the error code may be unrelated too.
In order to compile your code as part of a C++ CLR console application project under VS2015, I first needed to comment out the line using namespace std;. Otherwise the compiler mistook your managed array as a reference to the C++ standard library array template. Besides this, I could leave your code unmodified; it doesn't use anything from that namespace anyway.
Using the following driver code, the program produced the expected output file content:
Code:
// Main.cpp
#include "stdafx.h"
#pragma unmanaged
#include <iostream>
extern "C" void _cdecl PAExch(double *Date, double *TimeSeries, double *out, int rf, long int size);
void NativeMain()
{
double adDates[10];
double dCurrentDate = 42835.427083333333333; // 4/10/2017 10:15:00 AM
for (int i = 0; i < 10; ++i)
{
adDates[i] = dCurrentDate;
dCurrentDate += 0.01041666666666666666666666666667; // 15 minutes
}
double adValues[] =
{
1.05807995796204,
1.05810713768005,
1.0581442117691,
1.05816948413849,
1.0581511259079,
1.05814778804779,
1.05817842483521,
1.0582081079483,
1.05821871757507,
1.05818438529968
};
double adOut[10];
PAExch(adDates, adValues, adOut, 1, 10);
for (int i = 0; i < 10; ++i)
std::cout << adOut[i] << std::endl;
}
#pragma managed
int main(array<System::String ^> ^args)
{
NativeMain();
return 0;
}
It is lacking the header line as shown in your initial post, which is no surprise, since there's no code at all provided to create it. Also the DateTime values are stored in the localized format. This should be unproblematic as long as it's always just your program reading back in the data, as DateTime::Parse() by default accepts the localized format as well. It may irritate other programs trying to read the file, though.
This is the console output produced by the program:
For all that to work, I had to provide a pre-existing PAT.dat file at the expected location, containing the eventual input and output file names. I used the same name twice, so the program reads back in the data that it just wrote to disk. Without that file the program fails with an uncaught FileNotFoundException.
Finally, first checking for existence of the output file and deleting it if it exists is unnecessary: File::Create() overwrites any pre-existing file anyway. Better, perhaps, check for existence of the intended output directory and create it if missing. Otherwise a missing output directory will lead to failure with an uncaught exception as well.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.