-7

The back story: I am trying to create an account on en.cppreference.com. part of the process involves: What is displayed by std::cout << "ev" << 'a';

The dilemma: I have no idea what the hell that is. I tried putting that into the terminal, but got nothing useful. I tried putting that in code and compiling it ... still no luck. I googled it, but got no closer to understanding what the hell they are asking me to do. and last but not least, I went to http://en.cppreference.com/w/cpp/io/cout

and found the following code, which I also tried to compile without luck.

#include <iostream>
struct Foo {
    int n;
    Foo() {
       std::cout << "static constructor\n";
    }
    ~Foo() {
       std::cout << "static destructor\n";
    }
};
Foo f; // static object
int main()
{
    std::cout << "main function\n";
}

attempts to compile it resulted in:

[bad_cat@KittyLitter LearningCode]$ gcc input.c
input.c:1:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.

All I'm trying to do is get past this, so I can create an account and learn about C programming.

DYZ
  • 55,249
  • 10
  • 64
  • 93
Vasqi
  • 125
  • 9
  • You use a C compiler (`gcc`) to compile code written in C++. You must use a C++ compiler, such as `g++`. – DYZ Feb 11 '17 at 19:31
  • 2
    You don't need a cppreference.com account to learn C. Everything on cppreference.com is available to you without logging in. Having an account only allows you to edit the wikis. – Emil Laine Feb 11 '17 at 19:40
  • @DYZ, thanks, that's good to know. I – Vasqi Feb 11 '17 at 19:43

4 Answers4

0

This is a C++ program and you are trying to compile using gcc compiler. Use g++ compiler to compile this program.

Rishi
  • 1,387
  • 10
  • 14
  • I was under the impression that gcc was c/c++ so I had attempted to compile as .c and .cpp thinking that I had covered that. But I just tried g++ input.cpp and that worked fine. Sorry but I am no longer able to mark your answer as correct, because my rep dropped from 16 to 10 as soon as I asked this question. – Vasqi Feb 11 '17 at 19:41
  • @Vasqi, that is okay. Note that `` is a C++ library. Glad to help. – Rishi Feb 11 '17 at 19:42
  • `gcc` is C/C++. You need to link the standard C++ libraries. – hm1912 Feb 11 '17 at 19:54
0

The code presented by you in a C++ program. You need to save it in file.cpp format, after that you need to compile with g++ file.cpp and it should work.

You have saved it file.c format and compiling it with gcc, which is C standard, not C++.

Shravan40
  • 8,922
  • 6
  • 28
  • 48
0

The gcc compiler is capable of compiling C++ code, see here. I think the problem is, that you compile with gcc input.c. Try changing the filename into input.cpp, as *.c files are C files and *.cpp files are C++ files. You also need to tell a linker, as the C++ are not linked by standard. So this should work: gcc input.cpp -lstdc++. You can also use the g++ compiler, where the libraries are linked by default.
To answer the other part of your question: std::cout is in fact std:: and cout. std ist just the console (in C it is stdout, I'm not sure if it is called the same in C++). And cout prints out text.

Community
  • 1
  • 1
hm1912
  • 314
  • 1
  • 10
  • Xeneda, I did make a failed attempt to compile as: gcc input.cpp before I came here to seek advice. – Vasqi Feb 11 '17 at 19:46
  • Try compiling with gcc input.cpp -lstdc++. This will link the standard C++ libraries. – hm1912 Feb 11 '17 at 19:52
0

std::cout prints given string in console. I recommend try some basic tutorial of C++, maybe this will be fine.

Two simpliest examples which should work:

#include <iostream>

int main()
{
  std::cout << "Hello World!";
}

And second (doing exactly the same):

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
}
Karol Selak
  • 4,248
  • 6
  • 35
  • 65