gnuplot.exe path not found for writing in c++ - c++

I'm new to gnuplot and was trying to just make a plot of random numbers to visualize the distribution of the psuedo-random rand() function in c++. However, I came across a problem that appears common: the path was not found for gnuplot.exe.
Possible relevant information before I go on:
Running Windows 10 64-bit. Compiler: CLion. gnuplot.exe path: C:\Program Files (x86)\gnuplot\bin I have the latest version of gnuplot form sourceforge (as of 10/21/19: 5.2.7 I believe).
I have already checked these questions:
gnuplot-cpp cannot feed command to pipe
Gnuplot & C++: Can't find gnuplot neither in PATH nor in "
I've looked through many other questions but they weren't as relevant to the problem I have. I tried implementing the answers there and did not make any progress. I have the same gnuplot_i.hpp file and changed the problem line to:
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
std::string Gnuplot::m_sGNUPlotFileName = "gnuplot.exe";
std::string Gnuplot::m_sGNUPlotPath = "C:/Program_Files(x86)/gnuplot/bin/";
I also have the correct PATH set for gnuplot as a environmental variable and can execute gnuplot from cmd.
The errors I've gotten were:
Cannot find gnuplot neither in PATH nor in "C:/Program_Files(x86)/gnuplot/bin"
and, when I removed the "_" from the path above and replaced it with a space:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
This last one is the only one that appears now, even though I do not have the space anymore, as it's been mentioned that having spaces in the path is a known bug with gnuplot. I am aware that Program_Files(x86) is not a real path, I was just trying to get rid of the second error message.
My main.cpp, if it even matters:
#include <iostream>
#include "gnuplot_i.h"
#include <cstdlib>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
try {
Gnuplot rand_plot("lines");
}
catch (GnuplotException ge) {
cout << ge.what() << endl;
}
return 0;
}
Any help on solving these errors would be greatly appreciated.

Botje in the comments solved the issue. Changing lines 1714-1715 in gnuplot_i.h to std::string tmp = std::string("\"") + Gnuplot::m_sGNUPlotPath + "/" + Gnuplot::m_sGNUPlotFileName + std::string("\""); fixed the problem.

Related

C++ - Simple hello world doesn't work in vscode

I've just started programming in c++ and I've a problem that is probably really simple but I've been trying to solve it for a long time.
Cout prints all built-in variables but when I try to print a string variable, it doesn't work (it doesn't print anything even if there are other couts with other things to print that aren't strings).
In short, when there's a string variable in the code, nothing works, at least that is what I noticed.
That doesn't print anything
#include <iostream>
#include <string>
using namespace std;
int main() {
string greeting="hello";
cout << greeting;
}
But that works:
cout << "hello";
I've tried the same exact code in online editors and it does work.
EDIT 1:
In the computer's terminal, this is what is shown: procedure entry point is not found ... in the dinamic link library ...
Path:
This is the mingw path: C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
EDIT 2
Finally solved it. I've copied the libstdc++ and the libgcc to where I have the .exe.Thank you all for your support. Special thanks to #HolyBlackCat.
The solution to errors like "procedure entry point is not found" is:
Make a list of all .dlls located in your compiler's bin directory.
Go through C:\Windows and C:\Windows\System32 and make sure none of those dlls are there. If you find any, move them somewhere else (or delete them).
Add your compiler's bin directory to the PATH, as the first entry.
I should see the whole code, but considering it doesn't work only with a string, probably you didn't use the namespace std:
Try this:
#include <iostream>
using namespace std;
int main()
{
string greeting = "Hello";
cout << greeting;
}
If it doesn't work, show me the whole code and I'll see if I can help!

Why does my c++ program output garbled code

I use MinGW64 to compile c++ programs. But since I upgraded to Windows 10, I found my c program output Chinese will be garbled code.
I follow the online method, adding a code in the program header: SetConsoleOutputCP(65001);, then it fixes. but I think it's so troublesome to do this for each c++ program. What should I do?
I think this is my system's problem, the same code in Windows 7 is not a problem, I just want to find a more convenient solution instead of adding the same code to every file
There's the code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
SetConsoleOutputCP(65001);
cout << "文本" ; //Output will be garbled code if there's no line above
return 0;
}
The console in most operating systems only expects ASCII character input. In order to show some other char set you have to specify that in your code. The SetConsoleOutputCP command sets the "code page" windows should read from. By the way not all versions of windows have the same code for this command.
Please refer to the documentation found here.
The documentation suggests using EnumSystemCodePages to make sure the code for that language exists on that system.
P.S.
Your English is very good :)
EDIT
I tested your code on my computer with Visual Studio 2019 and got the following
Warning C4566 character represented by universal-character-name '\u6587' cannot be represented in the current code page (1255)
even with the SetConsoleOutputCP command you added. I assume you need to have chines installed for this to work. The problem is that I don't have the relevant code page for the windows console to look in for the char set. see this answer and this answer.

Inputting values from .mat file to array in C++

I am trying to copy a 1100x1100 matrix from a .mat file to an array variable of type float in C++. I read online and found that the matio library is a good option. I installed their library using "make" on Ubuntu 12.04 (I followed the method given on their webpage).
However, I am unable to write code using it mainly because I am new to C++. I am using g++ to compile the file. I get errors such as "unknown reference to Mat_Open" and so on.
I did find this bit of code on the webpage:
#include <stdlib.h>
#include <stdio.h>
#include "matio.h"
int main(int argc,char **argv)
{
mat_t *matfp;
matvar_t *matvar;
matfp = Mat_Open(argv[1],MAT_ACC_RDONLY); //here argv[1] is "a.mat"?
if ( NULL == matfp )
{
fprintf(stderr,"Error opening MAT file %s0,argv[1]);
return EXIT_FAILURE;
}
matvar = Mat_VarReadInfo(matfp,"x"); // x is the variable we are trying to access?
if ( NULL == matvar )
{
fprintf(stderr,"Variable ’x’ not found, or error reading MAT file\n");
}
I have a couple of questions:
here, argv[1] corresponds to the .mat file I am trying to open right?
x in this code is the variable present in the .mat file I am trying to copy?
When I ran this code, I received errors stating - Unknown reference to Mat_Open and so on. Another couple of the same type of errors also were there.
I compiled this using : g++ abc.cpp -o test. (Followed by ./test. But I never got around to that due to the errors obtained during compilation).
How can I make it work? Is there any mistake with the code I used? Or with the compile statement I am using-maybe there are some linkers I need to use for compilation.
Thank you. Please remember that I am new to C++. Any advice would be helpful.
1) argv[1] - is a first parameter you put after your program call. If you want to "feel it", use debugger or code like this:
#include <iostream>
for (unsigned i = 0; i < argc; ++i)
{
std::cout << argv[i] << std::endl;
}
2) Yes, looking at http://libmatio.sourcearchive.com/documentation/1.3.4/group__MAT_g4c8205ff25c5b688a40775fbb1840b7e.html I can say, that you will read variable with name "x".
3) "undefined reference" means you need to build with matio libraries. Add something like "-lLibraryName" to your compile string. And it will have to be built.
To avoid many problems, try to install Code::Blocks, it's cross-platform and quite easy to start using C++ if you never did it before. It also supports debuggers, so you will avoid many problems quite easy.

Beginner questions about vim

Question #1:
if I have a C++ code like this
#include <iostream>
using namesapce std;
int main() {
int a;
cin >> a;
cout << a << endl;
return 0;
}
I don't know if this is called (debugging, compiling, or building), but I just want to run this program inside gvim so I can give it the input and see the output, and see errors such as "missing ';' " or "missing '}' " (like what happens when I click F9 in "Code::Blocks").
exe file, and other things are not important for me.
Question #2:
if I have a C++ code that I write every time like this
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
How can I make vim insert this code every time I open a .cpp file with vim ?
I have Windows 7 32-bit and my .vimrc file is the default one that comes when I install vim.
Please be as detailed as possible.
Probably this is what you are looking for
Vi and Vim Autocommand: 3 Steps to Add Custom Header To Your File Automatically
Q1: You'll need to compile your C++ code first to "see errors such as "missing ';' " or "missing '}'". Then you can run your compiled EXE to determine if your input and output values work. In Visual Studio, hitting the play button (Debug) will do both.
Q2: vim has a set of events that occur that allow you to perform certain actions, like append text to a new file with an extension of .cpp. You would add some code to your .vimrc file to do this.
If you just want it on opening up use autocmd. You can do it like lipun4u said:
Vim autocommand auto add headers at start of file
Well I suggest getting this plugin: snipMate
snipMate.vim aims to be an unobtrusive, concise vim script that implements some of TextMate's snippets features in Vim. A snippet is a piece of often-typed text that you can insert into your document using a trigger word followed by a tab.
It has several features:
More than 1 language supported
Lots of premade snippets
Ability to make your own snippets
So this way you can have different headers for different programs, and just assign them to a hot key.

C++: Unable to resolve identifier cout, Netbeans, Ubuntu

I am using C++ on Netbeans 7.1 on Ubuntu 11.04. For some reason, the following code results in the error message "Unable to resolve identifier cout".
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello,world!\n";
return 0;
}
Any help resolving this problem would be greatly appreciated.
The solution for your problem is at least strange ;)
Once iostream header is added, one has to reparse code. Click right on a project, go to code assistance and click to reparse project. Worked for me.
I was using netbeans for mac.
check whether iostream is really getting included;
i have tried your code on my machine using eclipse cdt it worked fine.so, please check the
includes.
What sort of file is this in? Is it a .h file, or .hpp file? I had this same issue. Netbeans can be ridiculous sometimes with C++. For me, I changed #include <iostream> to #include<iostream.h>
This may seem too simple, but...
In my NetBeans installation, when I go to create a new project, specify C/C++, it brings up a dialog box prompting for "Project Name:", location, folder, makefile name, and then...
a check box for "Create Main File", an edit box with "main" filled in, and to the right of that is a drop down list that reads "C". If you hit Finish, this will create "main.c" (C, but NOT a C++ file). Instead, in the drop down list, select "C++". Then the IDE creates main.cpp, which will be compiled with g++ and will find those includes and functions.
There is a difference between std::cout and cout. You don't currently have std::cout defined in your file. std::cout is a c standard out. In C++ we only need cout to work with iostream.
If you must use a standard c out then do the following:
Add this to the top under iostream
#include <iostream> //Input output stream in C++
#include <cstdlib> //Stands for c standard library
using namespace std;
Your code will now work because:
This change defines std::cout and std::cin among other things. (standard in, standard out respectively.)
However, I'd recommend this alternative if you don't need standard in outs:
Replace std::cout with cout, because cout is defined in iostream in C++. Your program would have worked without the std:: portion of your cin cout commands because you originally included iostream.
Try taking out the using namespace std; - it's generally considered bad form anyway :-)
I'm not sure that will fix the problem but most people either use the namespace or fully qualify things like std::cout. I've never seen code that does both.
The other thing to check is that the iostream header actually is being bought in. In other words, are there any errors on that line. A lot of problems (at least in the Windows world, so it may not necessarily apply to you) seem to be due to faulty path setup in NetBeans.
Hey look at your Output Debug. You may see "no permission". After I changed the file permission of "/YourProjekt/dist/Debug/GNU-Linux/file" to runable and everyone can read and write the error disappeared. (BTW: I had the bug because I was on a NTFS System with my Projekt, it have to be ext partition)
Hope I can help you with that.
Try taking out the std:: next to cout