I am trying to compile the simple Hello World! program from this tutorial LEDA Tutorial, section 1.3 using LEDA 6.1 on the UNIX system of my department.
#include <LEDA/core/string.h>
#include <iostream>
using leda::string;
using std::cout;
int main ()
{
string msg = "Hello World!";
cout << msg << "\n";
}
After setting the environment variable
LEDAROOT = /usr/local/LEDA-6.1
export LEDAROOT
I try to compile the file leda1.c containing the upper code
g++ -c leda1.c -I$LEDAROOT/incl
I get some errors witch are:
In file included from /usr/local/LEDA-6.1/incl/LEDA/system/basic.h:70,
from /usr/local/LEDA-6.1/incl/LEDA/core/string.h:16,
from leda1.c:1:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h: In function ‘int leda::Max_Value(int&)’:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h:120: error: ‘INT_MAX’ was not declared in this scope
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h: In function ‘int leda::Min_Value(int&)’:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h:121: error: ‘INT_MAX’ was not declared in this scope
Can anyone help me with this problem?
Related
I'm trying compile this code in cmd:
#include <iostream>
#include <string>
using namespace std;
int main(){
int n = 24;
string s = to_string(n);
cout<<s;
}
I found in another qestions, that I should use this command:
g++ -std=c++11 main.cpp
but I get error:
main.cpp: In function 'int main()':
main.cpp:7:24: error: 'to_string' was not declared in this scope
string s = to_string(n);
^
I have latest g++ compiler for Windows v. 5.3.0. I used this installer for MinGW.
I tried solve in to_string is not a member of std, says g++, but this patch doesn't work.
How can I compile this code in command line in Windows?
On one of my Mac box, for simple Hello Word C++ program, there are such compile error, other Macs I am working on are ok. Using even the same version of Eclipse CDT 64-bit Mars.
Posted error and Hello Word program, does anyone have any hints? Thanks.
//============================================================================
// Name : Test1.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Attach error from g++ of command line,
g++ Test1.cpp
Test1.cpp:9:20: error: iostream: No such file or directory
Test1.cpp: In function ‘int main()’:
Test1.cpp:13: error: ‘cout’ was not declared in this scope
Test1.cpp:13: error: ‘endl’ was not declared in this scope
In summary, if whether you're developing in C, C++ or Objective C on the Mac, you probably just want to use XCode.
Not sure what Eclipse was doing, but (see link in comments) earlier versions of Eclipse might work where later ones will not.
I've got some code that I'm running on Mac OS X that can't be compiled on the Virtual Machine running Linux Mint. This is a simple example. When I run it in Mac, all is fine, but I'm getting issues when I run the same code on Linux, so I'm assuming the library I'm including is not there, but should I be getting an include error then?
Here's the example code that runs on Mac.
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
for (int i = 0; i < 10; i++){
string test = to_string(i);
cout << test << endl;
}
cout << "done" << endl;
return 0;
}
I get no issues here but running on Linux Mint, I get this when I try to compile:
for.cpp: In function 'int main()':
for.cpp:7:28 error: 'to_string' was not declared in this scope
string test = to_string(i);
^
make: *** [for] Error 1
Am I missing something? Any help would be much appreciated!
edit
I realize I forgot to include <string> on here and I fixed it, but what I changed (<string> included) still doesn't compile on Linux. I've used to_string before. I know that much in C++. I also tried adding <cstdlib>. Once again, this DOES compile on Mac and DOES NOT compile on Linux.
Here is my OSX output:
0
1
2
3
4
5
6
7
8
9
done
Here is my output on Linux Mint (Once again, Virtual Box, g++ make):
test.cpp: In function ‘int main()’:
test.cpp:9:28: error: ‘to_string’ was not declared in this scope
string test = to_string(i);
^
make: *** [test] Error 1
You could reproduce the problem yourself if you don't believe me. It's the same code, you can see for yourself if you want.
Compile your for.cpp file like this:
g++ -std=c++11 for.cpp
and run it with:
./a.out
The support for the to_string function in the <string> header was added in the C++11 version of the language, so you need to tell GCC to use that version. You can use the c++0x flag too, for example:
g++ -std=c++0x for.cpp
And you don't have to worry about <cstdlib>, that has nothing to do with it...
to_string() is defined in <string> if you are compiling with C++11 (but is not defined, or unreliably defined as an extension feature, if you are compiling with an earlier version of C++).
Reference: http://en.cppreference.com/w/cpp/string/basic_string/to_string
SOLUTION:
I found a better solution. For some reason, I've read stdlib.h will not work on some linux systems. I used a different function to convert int to string.
on linux:
#include <stdio.h>
and then
for (int i = 0; i < 10; i++){
char buffer[10];
sprintf(buffer,"%d",i);
string stringInt = buffer;
cout << stringInt << endl;
// do whatever you want with the string
}
edit
To the person that down voted my solution to this, here's a post from six years ago basically saying the same thing.
I'm having some trouble using Notepad++ to compile code. I've installed notepad++ (and NppExec), downloaded MinGW from this source (http://nuwen.net/mingw.html) and installed it to "C:\MinGW\".
Then I tried to set notepad++ to use g++ to compile c++. Per advice, I entered the following into NppExec's console:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"
Saved it as C++ Compiler, and added it to the "Macros" section of the toolbar.
Then I tried to run a simple test program:
#include <iostream>
int main()
{
cout << "Hello, world!";
}
After that a couple of weird errors popped up. First it wanted me to save to System32 by default, which I don't remember it doing before (it won't let me, forcing me to save in Documents).
I let it save to documents, than tried to run it with the compiler. It gives me this error, which I don't recognize at all:
NPP_EXEC: "C++ Compiler"
NPP_SAVE: C:\Users\Bova\Documents\Test.cpp
CD: C:\Users\Bova\Documents
Current directory: C:\Users\Bova\Documents
C:\MinGW\bin\g++.exe -g "Test.cpp"
Process started >>>
Test.cpp: In function 'int main()':
Test.cpp:5:5: error: 'cout' was not declared in this scope
cout << "Hello, world!";
^
Test.cpp:5:5: note: suggested alternative:
In file included from Test.cpp:1:0:
c:\mingw\include\c++\4.8.2\iostream:61:18: note: 'std::cout'
extern ostream cout; /// Linked to standard output
^
<<< Process finished. (Exit code 1)
Please help.
There is nothing wrong with your compiler. You are not using the correct namespace to use cout
#include <iostream>
int main()
{
std::cout << "Hello, world!";
}
Or
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!";
}
can i use Symbolic C++ features in linux c++ compiler or in visual c++ 2010? and also one question sometimes in programs there is such headers code
#include <iostream>
#include "symbolicc++.h"
using namespace std;
int main(void)
{
Symbolic x("x");
cout << integrate(x+1, x); // => 1/2*x^(2)+x
Symbolic y("y");
cout << df(y, x); // => 0
cout << df(y[x], x); // => df(y[x],x)
cout << df(exp(cos(y[x])), x); // => -sin(y[x])*df(y[x],x)*e^cos(y[x])
return 0;
}
header #include "symbolicc++.h" i have tried
#include " " but it does not show me symbolicc++.h so how to do it please give me a few example
there is such error after compile
symbolic.cpp:2:25: error: symbolicc++.h: No such file or directory
symbolic.cpp: In function ‘int main()’:
symbolic.cpp:7: error: ‘Symbolic’ was not declared in this scope
symbolic.cpp:7: error: expected ‘;’ before ‘x’
symbolic.cpp:8: error: ‘x’ was not declared in this scope
symbolic.cpp:8: error: ‘integrate’ was not declared in this scope
symbolic.cpp:9: error: expected ‘;’ before ‘y’
symbolic.cpp:10: error: ‘y’ was not declared in this scope
symbolic.cpp:10: error: ‘df’ was not declared in this scope
symbolic.cpp:12: error: ‘cos’ was not declared in this scope
symbolic.cpp:12: error: ‘exp’ was not declared in this scope
Go to http://issc.uj.ac.za/symbolic/symbolic.html , download e.g. the SymbolicC++3 3.34 gzipped tar file.
Unpack that tar.gz file, and adjust your compiler/IDE to search for additional header files in the headers/subdir.
e.g. using a command line on Linux:
[nos#localhost ~]$ wget http://issc.uj.ac.za/symbolic/sources/SymbolicC++3-3.34.tar.gz
16:20:24 (109.71 KB/s) - `SymbolicC++3-3.34.tar.gz' saved [155572/155572]
[nos#localhost ~]$ mkdir symbolicc++
[nos#localhost ~]$ cd symbolicc++/ && tar -xvzf ../SymbolicC++3-3.34.tar.gz ; cd ..
[nos#localhost ~]$ gcc -Wall -I/home/nos/symbolicc++/headers -o myprogram myprogram.cpp
Some clarification to extremely helpful nos answer - you have to change gcc into g++ compiler for newer versions of GNU compilers. Here is simple GNU Makefile that compiles example/lagrange.cpp example:
PROGRAM=legendre.cpp #program to compile
LIB=../headers #localization of headers of symbolicc++ library, specifically symbolicc++.h file
run:
g++ -I$(LIB) -o main.x $(PROGRAM)
(time ./main.x)
clean: main.x
-rm main.x