The program does compile but it is not running (the black screen doesn't show up). I have tried the following steps:
Reinstall the program after deleting it (didn't work)
Uninstall the program using YourUninstaller.exe, which is a program that deletes everything even the reg files (didn't work either)
So what happened?
Here is the code that I have tried:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout<<"hello You~~"<< endl;
system("PAUSE");
return 0;
}
conio.h and at the end of the program getch();.
This helped me with the same problem in Borland C++ installed on win xp on a virtual machine.
The problem is with your anti-virus, its blocking your binaries.
Reinstall dev c++ when your antivirus is disabled.
After installation enable anti-virus if it blocks again, go add an exception in anti-virus program
Better use sleep(1) instead of calling subprocess.
cout<<"hello You~~"<< endl;
sleep(1);
Edit: sleep(1) works fine under Linux but as well-suggested
by #user786653 use of cin.get() is recommended, and is closer than PAUSE:
#include <iostream>
using namespace std;
int main() {
cout << "hello You~~" << endl;
cin.get();
return 0;
}
The same problem is also faced by me in newest version of Dev
i just uses the header file #include <bits/stdc++.h> in initial
and with this use getchar() just before return 0 statement in last of program.
it works definitely please remember getchar() is just before returen statement , not after return statement.
Related
I am new to C++.I am following freeCodeCamp.org tutorial on C++.
The program looks like this-
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int luckyNums[] = {4,8,15,16,23,42};
cout << luckyNums[2];
return 0;
}
since I had VS code already installed I did not install code blocks.
Every time I run the above program I get an error "Access is denied". Also at the same time McAfee pops up saying "we just stopped a virus". I couldn't find a solution to this on Google anywhere.
When I was trying to do something with the code, in line 6 I did
cout << luckyNums[2] << endl;
and it worked and returned 15 but now the problem was I didn't understand why it worked because Mike got the result without doing this in code blocks.
Mike is the person giving the tutorial on freeCodeCamp.org
Running the code returns no errors, the problem is when I try to exit the program.
Simply, when i use the exit, return or abort functions, i get this (picture below)
see code below
//First 2 libs handle info exchange
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std;
main(){
string username;
cout << "Please enter a general use handel (\"username\")\n";
cin >> username;
fstream blockUsername;
blockUsername.open("Player_Data/username.txt", ios::out); //out is for writing, in is for reading
blockUsername << username;
blockUsername.close();
return 0;
}
I'm aware that similar questions have been asked, but I have not succeeded in fixing my code with those.
What I want is for the program to close with no exit values, even though I know that they are useful.
PS: It very well could be something to do with my code editor (Dev C++), or my compiler which i broke and had to fix recently.
Also side note how would i go about removing that address at the top of the terminal (and potentially replacing it with something else)?
These are printed by your IDE....if u execute the .exe output of this code...the console would just disappear after program exits and it would not be shown
Peace
try using return 0; wherever you want to exit, it's okay to have more than one return 0; in your code or to simply put it after an if statement.
that's my first use to code block but it hasn't gone fine ,, i face a really weird problem
i cant even describe it so i will just tell you what's happened.
the problem is that the ide dont compile my project even if the code were correct
its just open a new tab that called "iostream" and the console window appears but empty
why do that happens ?
look to the code which the ide face a problem while compiling it ,, simplest code ever
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
and this is the compiling results...
thats all..
will codeblocks stop annoying me ?
This line is not valid syntax
usingnamespace std;
Those are two separate keywords
using namespace std;
And since you are just starting C++, Lesson 1: Don't do that.
While running a program in Visual Studio C++ editor, when i click on Local Windows Debugger, the command prompt window opens up, where i am asked to input data (depending on my program). The problem is the window doesn't stay very long after the output is shown.
What do i need to do to keep the window up for a longer time, or at least until i close the window myself?
I tried for over half hour to check various options and see if there is anything that can be done to prolong the duration.
Thanks and regards,
Nikhil Kenvetil
Try to use one of the below methods to add some codes at the end of the main() function:
getchar();
char ch;
cin>>ch;
Try this:
#include <iostream>
#include "conio.h"
int main()
{
std::cout << "Hello World\n";
getch();
return 0;
}
you could try using system("PAUSE");
When I look in windows task manage it says it's using 3 threads? Why is this? I was expecting just 1 thread to be used.
I used Netbeans IDE and MinGW-Windows g++ to compile it.
Thanks
Code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
int input;
cin >> input;
return (EXIT_SUCCESS);
}
Maybe Netbeans put some wrapper for internal purpose ? (debugging, profilling, ...) Anyway it don't matter because you didn't create it : these threads should not interfere with your program and your program will not interfere with them.
I don't use Task Manager or Netbeans, but can I suggest you may have misread the output:
one thread to start a shell
one thread for the shell to execute your program
one thread for your program's executable
Total 3. None except the last have anything to do with C++.