When I use clang-format to format my C++ code in sublime text3, I received that error iostream file not found.
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
cout << "HELLO, Captain Teemo!" << endl;
return 0;
}
But I can run the c++ code with Command+B.
I also can compile the c++ code in command line.
Related
after google search, I came up with this Solution
g++ finlename.cpp -I{include file directory address} -L{Library file directory address}
-l(linkeroptions)
seems like this doesn't work for me. when I compile using this I get an error stating:- cannot find the headername.h(header file that was included in my program of the external lib).
file:-
#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv)
{
cout << "Hello world!" << endl;
return 0;
}
I am trying to use Gnuplot on Windows with gnuplot_i.hpp. When I type "gnuplot" into cmd everthing works, so the PATH variable should be set correctly. This is my code:
#include <iostream>
#include "gnuplot_i.hpp"
using std::cout;
using std::endl;
int main(int argc, char* argv[]) {
try {
Gnuplot g1("lines");
} catch (GnuplotException ge) {
cout << ge.what() << endl;
}
return 0;
}
The output is Can't find gnuplot neither in PATH nor in "C:/program files/gnuplot/bin" .
When I add the line
Gnuplot::set_GNUPlotPath("C:/gnuplot/bin/");
it just changes to Can't find gnuplot neither in PATH nor in "".
What am I doing wrong here?
Found the answer myself: For some reason gnuplot_i.hpp expects your exe to be called pgnuplot.exe instead of gnuplot.exe ... Now everything works.
I don't know whether I have installed cygwin wrong or what but the code compiles fine but it doesn't show the output. Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string name;
cout << "Enter the name of the person" << endl;
getline(cin, name);
cout << "Name is: " << name << endl;
return 0;
}
Here's the compilation image and the execution:
Your code is fine. The correct way to call the executable using Cygwin is ./string.exe
As I can see, you use cygwin. I had the same issue with gcc 5.2. Try to install gcc 4.9 and all corresponding libraries for this version instead.
I made an Xcode project. Like this:
Mac OS X -> Application -> Command Line Tool
I chose C++
And then I saved it in a folder.
Now I opened it in Xcode, there is a file named main.cpp under the project name title, so I opened that.
So main.cpp contains (location: Desktop/CPP/learn/learn/main.cpp)
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Now I click on File > New File and I selected C++ file without header, I named it main1.cpp
So that main1.cpp now just has
#include <stdio.h>
I replaced that and made main1.cpp to
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "MAIN1DOTCPP!\n";
return 0;
}
Then I ran main1.cpp, And the out put was "Hello World", I have been trying to get the output of the second file, That is "MAIN1DOTCPP" for like 2 hours now, Can someone please help?
I try to run the code blow in Xcode 4.2:
int main(int argc, const char * argv[])
{
locale loc("chs");
locale::global(loc);
wstring text(L"你好");
wcout << text << endl;
return 0;
}
I got a error "Thread 1:signal SIGABRT".
Can you Tell me why the error happen or how to use wstring and wcout to output the Chinese words?
You don't. Mac, like other Unix systems, uses UTF8 while Windows uses "Unicode" (UTF-16).
You can print that perfectly well on Mac by using string and cout instead of wstring and wcout.
ADDENDUM
This sample works great. Compile with g++ and run as-is.
#include <string>
#include <iostream>
using namespace std;
int main(int arg, char **argv)
{
string text("汉语");
cout << text << endl;
return 0;
}
The crash is coming from the call to locale(). This SO answer seems related.
As mentioned by Mahmoud Al-Qudsi, you don't need it as you can use UTF-8 in a normal string object:
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
string text("你好");
cout<<text<<endl;
return 0;
}
Produces:
$ ./test
你好
EDIT: Oops, too late :)