How do I compile?
Im trying to compile this simple ******
#include <iostream> int main(void) { cout << "WORK FFS!"; cout << "\n"; return 0; } what have I done wrong? beacouse it says when i try to compile cc test.cpp ali@pullansreturn:~/programing$ cc test.cpp test.cpp: In function 'int main()': test.cpp:6: error: 'cout' was not declared in this scope and where does the runnable file get when if I ever succeding compiling? seriously i dont know whats wrong. HELP! |
if you compile your program with the following command
Code:
g++ -o test.o test.cpp Code:
./test.o Your code is using cout which resides in the std namespace and so you will need to modify each cout, what follows is an example of what you will need to do: Code:
std::cout << "Hello"; |
OK, I have seen how people use "using namespace std;" but it doesnt work, i guess it does the same thing as std::cout << "Hello"; But it still doesnt work
include <iostream> int main(void) using namespace std; { cout << "WORK FFS!"; cout << "\n"; return 0; } ali@pullansreturn:~/programing$ g++ -o test.o test.cpp test.cpp:3: error: expected initializer before 'using' test.cpp:5: error: expected unqualified-id before '{' token ali@pullansreturn:~/programing$ |
#include <iostream>
using namespace std; int main(void) { cout << "WORK FFS!"; cout << "\n"; return 0; } ~ ~ it works now! thanks! |
(nevermind)
|
Yeah i know what you were going to mention, that int main(void) is the head of the { } body and that i typed using namspace std; between them
|
Indeed using std:: each time you use a function from the standard libraries is the same as putting in a using namespace std; at the start of the file however I have a preference towards std:: because it makes it quite clear that it is a standard function that is being used.
Also you can replace a "\n" with a std::endl which can all be on one line as follows: Code:
std::cout << "Hello" << std::endl; |
well to make this clear, im a total noob in all aspects of programing, i just started for like an half hour ago :)
so i dont really know what to do, i dont even know what using namespaces std; is not even int main(void) lol :) |
All times are GMT -5. The time now is 03:28 AM. |