hi, new here, problems with stdio

Pages: 12
i just started, and i am trying to do my first programme, but i have syntax errors telling me that no such file or directry as stdio.h.
please help guys, thanks
post you source code, maybe i could help.
man i'm totally new i dont even know what a source code is :-(. but i use windows home editions as my operating system, i just started C++
1 #include <iostream>
2
3 int main()
4 {
5 std::cout << "Welcome to C++!\n";
6
7 system("PAUSE");
8 return 0;
9 }

this is a source code , usually the first programm everyone starts
is was a hellow programme

#include < stdio.h>
int main()
{
printf("Hello World\n");
return0;
}

#include <iostream>
int main()
{
printf("Hello World\n");
return 0;
}

you need "iostream" instead of stdio.h , and return0 has to be seperated return 0;
#include <iostream> - is includes the contents of the iostream header file in the program which is needed for input and output of data.
Thanks man, now i can get started and learn more, thanks very much, i experienced a problem in the source code you posted, 3 errors on line 3,
expected unqualified-id before" int"
expected constractor, destractor or type conversion before 'int"
expected '; or ';' before "int"

these errors keep showing up, i dont why
it better to practice writng
#include<stdio.h>
#include<iostream.h>

as a library for your program.
ajax, look at the error message your getting from your compiler and think about spacing requirements, although spacing is not required in most area's of the code it is good practice and is required for many statements

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <iostream> 
using namespace std;
int main()

{

  cout << "Welcome to C++!\n"; 

  system("PAUSE");
  return 0;

 } 
Last edited on
sometimes .h extension is omitted so try
#include <stdio>
printf is declared in the legacy C header stdio.h. To use it in C++, you
should #include <cstdio>, as cstdio is the new C++ header for it.

cout is declared in iostream: #include <iostream>

it is a matter of the compiler, the code I wrote would work perfectly with dev-c++.
it seems that BettyBoopTS uses dev-c++
As for the original stdio issue it's either
<cstdio>
or
"stdio.h"
If you have the .h it belongs in quotes. Angle brackets are for standard libraries and are generally not followed by an extension.
that last statement is false
<header> is for headers located in the compiler's header directories,
"header" is for user defined headers
I wonder why ppl still uses 'system("anything");'?
make a define:
//This might be in another header file, and remember to include <climits>
1
2
3
#define pause()     cin.ignore(numeric_limits<streamsize>::max(), '\n'); \
                               cout << "Press ENTER!!!\n"; \
                               cin.ignore(numeric_limits<streamsize>::max(), '\n') 

Last edited on
Try to get the inherited functions/features of C are just part of C++ as well. If you include stdio.h or cstdio it's the same thing. The preprocesor knows where to look (actually the same place). Use < > !
1
2
3
4
5
inline void pause()
{
    cout << "Press ENTER!!!\n";
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
}


fixed.

Macros are evil.
I'm a beginner myself, but I think I can help.
This is your code:
1
2
3
4
5
6
#include < stdio.h>
int main()
{
printf("Hello World\n");
return0;
}

Assuming that you mean to write this program in C, this is the corrected code:
1
2
3
4
5
6
#include <stdio.h> //Notice that I removed the space
int main()
{
     printf("Hello, world!\n"); //this indentation isn't necessary, but it makes code more readable
     return 0; //You should separate return and 0;
}

Assuming that you mean to write this program in C++, this is the corrected code:
1
2
3
4
5
6
7
#include <iostream> //include iostream. You might have to change this to iostream.h
using namespace std; //this line isn't always necessary, but in some compilers, you might have to
int main()
{
     cout << "Hello, world!\n";
     return 0;
}

Another tip: If you don't want to have to write "return 0;", you can always say "void main()" instead of "int main()". It isn't ANSI legal, but it will compile, and do exactly the same thing.

One more tip: If you're trying to compile with Linux, you might have to install g++ and the build-essential package to be able to compile code in C or C++. Use the following commands:

/sudo apt-get install g++

/sudo apt-get install build-essential

Again, I'm a beginner myself, but I hope this helps. Good luck!
hey guys thanks for your help but i have a problem with this compiler i have deleted it, is there any one who knows a good website to which i can get a free, compiler, and is there any one recommending that i start with another language before C++, e.g phython, java e.c.t,
thank you very much guys,
closed account (S6k9GNh0)
Just thought I'd add that in C++, standard headers are to be included without a .h at the end at all times. Anything with .h at the end is deprecated in C++ (unless the header is non-standard).
Last edited on
Pages: 12