Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to parse one text file and get 3 parameters values out of it. I want to store this data in structure array and pass this structure array to one cpp file. What kind of data structure should I use in perl and how should I collect that structure array in cpp file?
Your question is somewhat unclear. Do you want the Perl program to generate source code that goes into a .cpp file before compilation, or do you want to read the output of a Perl program from a running C++ program?
Perl has a single array type, so you would use that for both cases.
If you are just using Perl to generate code, have it write a code fragment to a file using plain print statements, then #include that in your C++ source.
If you want to read the output of a Perl script from a running C++ program, and it is simple values that do not contain spaces or otherwise need escaping, you can simply use popen(3) to launch the script and fscanf(3) to read its output; then have the Perl script just output in a fscanf-compatible format with e.g. print "#result";.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i'm learning the basics of c++.
also at the same time i try to aplly what i've learned into a project.
i'm trying to make a GUI program for a command-line program.
the purpose of that program is to interact with PS2 Hard Drives, and i want to automate almost every feature it has.
the first thing i'm trying to do is parse a text file dumped by the program:
the text file contains a list of elements.
every element will contain this :
"media" "size" "Region Code" "name of the game"
Also, at the end of the file the total,used and free space of the HDD is written:
total 305152MB, used 199296MB, available 105856MB
I need to store into arrays (or vectors) the data of every game and the HDD space
Here's an example of what the text file looks like
https://mega.nz/file/o85SmLBZ#qf8FCXByI5-icz9LlSNFGiL7JXFArpwxODDLNrQ1LPc
Whatever I write to handle this will be executed several times (after erasing or installing games)
If you want to read and write to and from files, I suppose your best bet is the fstream library, which well... is used specifically to do that.
Here is a simple tutorial for the most fundamental ways to use the library.
Using this, you will read the file. There are examples for reading values one-by-one, but since the last line is specific, you might want to look into getline which shows up in that tutorial too.
Parsing it is the logic of your program, so I guess the first thing you want to do is put the values you read into arrays of some sort.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am testing a C/C++ application. For the majority of methods I was able to write unit tests using CppUTest.
But there are a few for which not, and I want to write integration/end to end tests to test these methods too.
What I want to test whether
correct output file is generated
for invalud arguments proper error messages are printed (it is a command line tool)
it displays correct output messgaes
My question is whether there are tools for this, or should I write some scripts to invoke my application, capture output etc.? If yes, how to start these scripts? Invoke them from CppUtest?
I know several ways to test for correct output:
If you use CMake and CTest, you can use CTest to compare the output of your program with the expected output. Does only work for text output (as screen output normally is), and will not work if you output random numbers of time/date and stuff like that. Look for add_test_output_check() in the CMake manuel.
If your program does not write hard-coded to stdout, then you could pass an std::ostringstream and afterwards test the contents of the string using your preferred unit test framework.
Last but not least you could use dup2() to define other file descriptors for stdout and stderr, execute the test and at the end check the contents of the file(s).
For the output file, I guess you have to create a reference output file and then compare the contents of this file with the file that was generated by the test: Write a test function that loads both files and does a memcmp() on the data.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to create a string array to hold the strings generated by a void function. I am very confused about if or how I can do this. The below code is giving me an error about "no suitable constructor."
getWords("theFile.dat"); // Function to extract list of strings from file
string wordsList[] = {getWords("theFile.dat")}; // Add strings from function to array
If (as your comment states) the code uses cout to print the strings, then you have no way to capture them and put them in your array. Well, ok, you might be able to, by doing some major/ugly hack that grabs hold of the stdout file descriptor and reads what is written to it, but that would just be ugly beyond words (and most likely would need different platform specific implementations). Just don't go there.
Write your own good function to read the file and return what you need or fix the crap function you've been given.
There's got to be a limit to how much crud (with the risk of introducing more crap/bugs) one has to add to work around broken crap code before fixing or re-implementing/re-factoring it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have previously asked a question, which is somewhat related to the present one, however, Please help a bit more.
As I understand it, from this link, I should be able to use redirect.stdin to a named pipe, then use a putc or binary write command to the pipe, and write unformatted data to it.
Nonetheless, I would love, that on the other end, a parallely running fortran process reads form one pipe, to which my D code writes in, and writes to another, from which i can read off, while in the D code.
Now problem is I don't find much information about named pipes in Fortran.
Before I use a C interface, to Fortran, is there any way to read pipes and write on a separate parallel pipe from Fortran?
EDIT: thanks for the hints, I sorted it.
I don't know much about Fortran but if you use the pipe redirection on the D side, the Fortran side just needs to use regular input read and output write functions, just like printing text to the screen, and it will be received on the D side.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
now i have some massive data on Excel Sheet, and i need by c++ program to transform this data into text file, to use it later in another thing.
how can i accesses this Excel file, to get data from first attribute and put delimiter and so on??
I have personally used Microsoft Excel Automation to read from Excel in the applications I develop. Please check the link http://www.codeproject.com/Articles/15837/Accessing-Excel-Spreadsheets-via-C for more information on Excel Automation.
But it seems there are other options as discussed in the following links
http://www.codeproject.com/Articles/42504/ExcelFormat-Library
Read cells from Excel in C++?