Jump to content

Help Requested

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
bodhi2016

bodhi2016

    Newbie

  • Members
  • PipPip
  • 29 posts
I have downloaded dev c++ .After clicking on the New in File option a submenu appeared , from there i selected New Project ,another dialog box appeared from there i selected console application and clicked on c++. TO TEST WHETHER THE COMPLIER WORKS PERFECTLY I JUST TYPED FEW LINES OF CODE AS BELOW:-
#include<iostream.h>
#include<conio.h>
void main()
{
     cout<<"hi";
          }
BUT ITS GIVING LOTS OF ERROR I AM USED TO TUBO C++ IN WHICH THERE USED TO BE A BLUE SCREEN. I HAVE AN AVERAGE KNOWLEDGE OF C++ I AM TRYING TO LEARN WIN32API ON MY OWN .PLLZTELL ME WHERE I AM GOING WRONG THE ERRORS ARE:-

Quote

1 D:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31, from my experiment.cpp In file included from D:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, from my experiment.cpp
1 D:\Dev-Cpp\my experiment.cpp from my experiment.cpp
32:2 D:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
4 D:\Dev-Cpp\my experiment.cpp `main' must return `int'
D:\Dev-Cpp\Makefile.win [Build Error] ["my experiment.o"] Error 1
(just for everybodys information
i NAMED THE FILE my experiment
and the project as project 5

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
The code you provided has never been and will never be standard C++.

1) You shall not use the .h-extension on C++-header-files.
2) conio.h is not a standard library.
3) The main-function shall always return an integer, and this integer shall always be 0.
4) The compiler is not able to find cout, as it's a part of the std-namespace, and you're not using the std-namespace.
5) Read the error-messages next time, and use the code-tags, when you're posting some code on CodeCall.

Here's the modified code:
#include <iostream>

int main()
{
    std::cout << "Hi" << std::endl;
    return 0;
}


#3
bodhi2016

bodhi2016

    Newbie

  • Members
  • PipPip
  • 29 posts
VOID i agree you know better than me but i also know something of c++. i am not returning any int from main function because i used void main not int mai.In turbo c++ we used to use
#include<iostream.h>
#include<conio.h>
and we used to use simple
cout<<"----";
cin>>----;
not all those
std ::cout
std::cin
For two years we have been taught c++ programming at school
we never saw these kind of syntax
WE used to use turbo c++ is programming in dev c++ different than in turbo c++
plZZZzzz explain .
your code is not giving errors but when i trying to run it, the dos windows appear for a sceond and disappear I used
getch();
but the same thing happend
VOID EXPLAIN ALL MY QUESTION DO NOT INTERPRET THIS MSG. AS IF I AM TRYING TO CHALLENGE YOUR KNOWELEDGE YOU KNOW MUCH BETTER THAN ME .i am really facing lots of trouble learnig WIN32API.I am spending 24x7 sitting at computer.Will you teach me everything that you know .Plzz brother will you help me. .Plzz forward all ebooks and online help file that you have .Since i will be having a series very very important exam within next 7 to 8 months so my mother is not willing to let me buy books oterwise my mind will be distracted from studies.So plzzz help me

#4
Frenzy123

Frenzy123

    Newbie

  • Members
  • PipPip
  • 15 posts
Hi there guys just been reading the post. vOid is right the .h extension is not needed it should be refered to as he has shown and the conion.h is not required.

I have to say though that the work that i have done surrounding C++ the main function doesn't have to return an integer. (but it usually does, although it will work without).

As far as the std namespace goes, some people declare the namespace at the top of the page as shown below;

using namespace std;

this way std:: doesn't need placing infront of each related function/command. but on small projects like yours vOid is definately right in using std:: in this way. As it is only needed once.(on bigger projects it probably should be declared at the top with the includes).

Finally the window is only flashing on and off because you aren't freezing the screen before it closes. This is done with the system command "pause". Hope this helps, see my version below.

#include <iostream>

using namespace std;

void main()
{
cout << "Hi people";

system ("pause");
};

#5
Rothzael

Rothzael

    Newbie

  • Members
  • PipPip
  • 27 posts
You can avoid the system command and make the program portable by just calling the program from the command line.
Programming Assignment Help
while(true) { cout << "Idiot!" << endl; }

#6
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts

bodhi2016 said:

i am not returning any int from main function because i used void main not int mai
According to the C++ language specifications, main() has to return an integer.

ISO/IEC 14882, 3.6.1.2 said:

It shall have a return type of type int [...]
I know it's not the latest specification, but I'm sure that this rule still exist in the newer specifications.


bodhi2016 said:

For two years we have been taught c++ programming at school
we never saw these kind of syntax
WE used to use turbo c++ is programming in dev c++ different than in turbo c++
plZZZzzz explain .
That's a shame you haven't learned about all this. Turbo C++ is known for many non-standard features it has built in. One of them is, that you don't have to specify the std-namespace. You should really get a better compiler, like GCC (pick MingW if you're under Windows)


bodhi2016 said:

your code is not giving errors but when i trying to run it, the dos windows appear for a sceond and disappear I used
Such programs are not meant to be staying on the screen. They'll naturally disappear, if you don't let them know, that they shall wait for userinput. This can be done in multiple ways, but the best way, in my opinion, is to simply run it through the terminal/commandprompt, like Rothzael also suggested.


bodhi2016 said:

.I am spending 24x7 sitting at computer.Will you teach me everything that you know .Plzz brother will you help me. .Plzz forward all ebooks and online help file that you have .Since i will be having a series very very important exam within next 7 to 8 months so my mother is not willing to let me buy books oterwise my mind will be distracted from studies.So plzzz help me
I'll sure help you, but I can't teach you everything. If you get problems in the future, you should create a new thread in this forum (CodeCall), and then I'll try to help you - and so will others do too.


In addition to Frenzy123's post, I'll add that it's also possible to only be using, some specific functions, classes, etc. from a namespace and not the whole namespace. This can be done like this:
using std::cout;
using std::endl;
// ...
cout << "Hello, World!" << endl;


#7
Frenzy123

Frenzy123

    Newbie

  • Members
  • PipPip
  • 15 posts
Can i just ask void. Is there any specific use of being able to specify which functions wish to use within a namespace at the beggining of a project surely it would be easier (if using more than 1 of) to just specify the whole namespace than particular functions, or is there a down side to this ?

#8
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Let's say that you for some reason have your own function or class called cout. You want to be able to print strings using it, but without using the std:: in front of each string declaration. In this situation you wouldn't be able use the whole std-namespace, because std::cout would be used too (as cout), and problems would occur, because of the same names.
// Bad
#include <iostream>
#include <string>
#include "my_cout.hpp" // For our own "cout"

// ...

using namespace std;

// ...

string MyString = "Hello, World!";
cout << MyString << endl; // Oops! Which cout to use?
// Good
#include <iostream>
#include <string>
#include "my_cout.hpp" // For our own "cout"

// ...

using std::string;
using std::endl;

// ...

string MyString = "Hello, World!";
cout << MyString << endl; // Ahh, now we know which cout to use!
Not the best examples, but I hope you get my point.

#9
Frenzy123

Frenzy123

    Newbie

  • Members
  • PipPip
  • 15 posts
Yea i get what you mean, erm but surely you would just not call it cout ??? you would call it conout or something else instead... ?

#10
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Of course, but now I'm not talking about the std-namespace in specific, but in general. I only used it as an example. If you're using tons of different libraries you could get in the situation that some functions and/or class-names would have the same name.

#11
Frenzy123

Frenzy123

    Newbie

  • Members
  • PipPip
  • 15 posts
yea i get ya. thx

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
If you have large code blocks where you need one and not the other, you could just declare your own namespace too, like so:


using namespace std;

//use std::cout by default here


namespace MyNameSpace

{

   //use your cout here

}


//back to using std::cout