-1

When I include the required library, the "#include.." line doesn't show any warning. But when I use the functions in that library, I find the Vim shows that "..use of undeclared function...". It seems that the library is not correctly included. So I want to know how to figure out this problem?

The screenshots for this question are attached as follows:

Syntax Error Warning

Setting for .ycm_extra_conf.py file

Barmar
  • 741,623
  • 53
  • 500
  • 612
Walden Lian
  • 95
  • 2
  • 10

1 Answers1

1

Try including it as follows:

#include <stdlib.h>  //use <> instead of  "" 

Also, the "printf" function comes from the "cstdio" library so try implementing that library as well,

#include <stdio.h>

UPDATED

The easiest way to fix that problem is;

Include the stdio.h library

#include <stdio.h>

Then, instead of typing;

printf('s');

you do,

printf("s");

Now, if you really want to print a character 's', then use,

printf("%c", 's');   // Tells the printf function that 's' is a character

The final code would look like;

#include <stdio.h>      
int main(int argc, char** argv) {
    printf("s"); 
    printf("%c", 's');
    return 0;
}

Now, your comment was that "cout" does not work. In order for "cout" to work you need to include the iostream library:

#include <iostream>

Then, you can use "cout" in your code;

std::cout << 's';
std::cout << "s";

Or you can include "namespace std" and the "iostream" library to avoid using std:: before "cout"

include <iostream>
using namespace std;

Thereafter, use cout without std::

cout << 's';
cout << "s";

The final code would be;

#include <iostream>
using namespace std;

int main(int argc, char** argv) {    
    cout << 's';
    cout << "s";
    return 0;
}

If you want to learn more about what is in the iostream library and how to use it I recommend using this site:

http://www.cplusplus.com/reference/iostream/

Also, for the stdio.h,

http://www.cplusplus.com/reference/cstdio/

ArtiomLK
  • 2,120
  • 20
  • 24
  • It still doesn't work. Actually the "...cout..." line also doesn't work when I include the iostream and using namespace std. So I think it doesn't result from this reason. – Walden Lian Sep 18 '16 at 13:38
  • I edited (UPDATED) the answer with step by step solution of your problem. – ArtiomLK Sep 18 '16 at 21:08