Cant open Output File .exe in Codeblocks IDE - c++

Whenever I compiled my C++ program in codeblocks ide, it runs but after once it show error that
"cannot open output file C:\Users\AkM\Desktop\code\g1.exe Invalid argument|" .
I had tried killing process(.exe file) from Task Manager, opening and closing codeblocks but same things happen all the time.
Please help, it really creates trouble for me while coding. This happens with almost every C++ program.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n ,m,k;
cin >> n >> m >> k;
int arr[n];
for(int i = 0;i<n;i++)
cin >> arr[i];
int l = n + m;
vector<int>vec[l];
int x,y;
for(int i =0;i<m;i++)
{
cin >> x>>y;
vec[x].push_back(y);
vec[y].push_back(x);
}
cout << vec[1][3] << endl;
vector<int >vv;
vector<int> v;
for(int i = 0;i<n;i++)
{
for(int j=0;j<vec[i].size();j++)
{
v.push_back(vec[i][j]);
cout << "hello" << endl;
cout << vec[i][j]<<" ";
cout << "hello" << endl;
cout << "hello" << endl;
}
sort(v.begin(),v.end(),greater<int>());
if(v.size()>k)
{
vv.push_back(1);
}
else
{cout << "hello" << endl;
vv.push_back(v[k-1]);
}
v.clear();
cout << endl;
}
for(int i =0;i<vv.size();i++)
cout << vv[i] << endl;
}
ERROR LINK :

This is a common error on IDE and modern systems. Most of the time, when you run a program, the executable file is kept open by the running program, and this is enough to prevent changes to the file => the link phase cannot complete.
The normal solution is just to ensure to close any running instance of the program before a build.
When there is a crash in a program launched from the IDE, the IDE can open the process in debug mode to allow the programmer to see what could have happened. In that case you must close that debug session before a new build.

Create a new project and by default it will create a main.cpp file in the project. Try to build the project and see if you face errors. If you don't see any error, replace the main.cpp contents with your code and build the project again. It did not result in runtime error for me and a console opened when I ran your program.

Related

How to search and use a file in ssh/server

My c++ program is being run on xCode. One part of my program is searching for a file that's on my computer and using it to store the values into an array. Everything is working just fine on xCode, but when I moved my files .cpp .h .txt into a server or ssh it doesn't seem to be working.
This is a snippet of my code:
case 'W':
if(heap.capacity == 0)
cout<< "Sorry!!! It cannot be done. Please initialize the heap first.";
else{
file.open("/Users/mbojo/Downloads/HEAPinput2.txt");
int line;
int count = 0;
while(file>>line)
count++;
file.close();
heap.capacity = count;
cout<< "COMMAND: " << choice << "\n" << "The capacity is "<<
heap.capacity << "\nSize is " << heap.size<<endl;
}
break;
Is there anything I need to change in ssh/server that can read the file.

Eclipse C++ Debugger doesn't stop at breakpoints and terminates immediately after debug started

I am following the C++ Debugging tutorial section (https://help.eclipse.org/photon/index.jsp) in the Eclipse Photon documentation. I have followed all the instructions creating the first C++ project and I'm at the 'Debugging project' section. My problem is that after I create my debug perspective and hit the 'Debug' button the debugger never stops on my set breakpoint. In the Debug window it just says and the loop of the program doesn't even produce any output at all. If you run the program normally the loop prints to the console, but nothing happens in debug perspective.
I have tried deleting my debug perspective and creating a new one and I'm having the same issues.
I have uploaded screenshots of my debug configuration.
https://imgur.com/a/MXYHxJl
https://imgur.com/a/eEU47Ht
https://imgur.com/a/koOf08x
#include <iostream>
using namespace std;
int main () {
// Say HelloWorld five times
for (int index = 0; index < 5; ++index)
cout << "HelloWorld!" << endl;
char input = 'i';
cout << "To exit, press 'm' then the 'Enter' key." << endl;
cin >> input;
while(input != 'm') {
cout << "You just entered '" << input << "'. "
<< "You need to enter 'm' to exit." << endl;
cin >> input;
}
cout << "Thank you. Exiting." << endl;
return 0;
}
I found a solution to my problem following instructions in this other post: Eclipse C++ MinGW - Can not Lauch Program <Terminated> The 2nd answer is what worked for me.
I had to right click on my project - - > properties - -> Run/Debug settings - - > click your launch configuration and click 'edit'. Once inside the edit screen click the 'environment' tab and add the following variable
Name = PATH
VALUE = %PATH%;C:\MINGW/BIN
I did not have anything set inside the environment and changing to the above has made the debugger stop at the correct breakpoints within the program.

eclipse debugger c++ - No source available for "std::ostream::operator<<

I am trying to run a simple program and use the eclipse dubgger but I keep receivng the following error:
No source available for "std::ostream::operator<<
The code:
int main()
{
int num1(0);
int num2 = 0;
std::cout << "Please enter the first number:" << std::endl ;
std::cin >> num1;
std::cout << "Please enter the second number:" << std::endl ;
std::cin >> num2;
}
BTW by trying to debug a simple 'hello world' ptogram I received the following error:
Can't find a source file at "C:\Users\DB\workspace\Temp\src\Temp.cpp"
Locate the file or edit the source lookup path to include its location.
I am using MinGW gcc compailer. I attached print screens for the configuratuon of the debugger.
debug configuratuion 2
debug configuratuion 3

visual studio 2013 debug mode and console don't working

I used visual studio 2013 two days ago.
But now... It does not working.
I tested below c code and cpp code.
//#include <stdio.h>
#include <iostream>
using namespace std;
void main(){
//printf("hi");
//cout << "test" << endl;
int a;
cin >> a;
cout << a;
}
The result of run is just blinking console.
And does not appear "Press Enter..."
result
If I try to debug then Visual studio stop and no response.
I do reset all options :(
Your console is showing the output but not waiting for you to see it.
you need to add break point or for workaround you can use
cout << a;
int ch = std::cin.get();
}
you must be able to see the value of a.
EDIT: ohh you would need fflush too, my fault too miss it.
cout << a;
fflush(stdin);
int ch = std::cin.get();
}

Visual Studio command prompt closes despite that I tried to stop it with cin.get()

My following basic C++ code isn't working. When I run it in Visual Studio express, it just closes the command prompt after I enter the second number. Thanks in advance.
#include <iostream>
using namespace std;
int main()
{
int num1, num2, answer;
cout << " Enter a number: ";
cin >> num1;
answer = num1 * num1;
cout << " the sum of the number is: " << answer << endl;
cout << "Enter a 2nd number";
cin >> num2;
answer = answer + num2;
cout << "The sum of the two numbers is: " << answer << endl;
cin.get();
return 0;
}
The problem is that there are characters left in the input buffer.
Anyway you shouldn't add "tricky" commands to keep the console open (you have to remember to remove them from the "production" code).
You can run your program Without debugger mode (CTRL + F5) and Visual Studio will keep the console application window open until you press a button (just check the settings in Project -> Properties -> Linker -> System -> Sub System -> Console (/SUBSYSTEM:CONSOLE)).
Of course, if you are debugging (F5), a breakpoint on the return 0; is the best option.
This is what is probably happening:
Last cin.get() reads the Enter key that you press after entering the second number. You need one more cin.get() so that the command prompt waits for you to press another key.