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
Related
I used to make basic program of C/C++ in vs code. After 2-3 weeks. in it's terminal it is not showing variable in output window. after making program when i run code.when i hit enter key it shows in terminal--it is not an error but code is not working.
PC C:\User\Owner\Desktop\C-C++>
WHEN I HIT ENTER IT AGAIN SHOW
PS C:\User\Owner\Desktop\C-C++>
IT DOES NOT SHOW 'ENTER VALUE OF B=='
IN THE TERMINAL OUTPUT WINDOW:-
for ex-:
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "ENTER VALUE OF A==";
cin >> a;
cout << "ENTER VALUE OF B==";
cin >> b;
c = a + b;
cout << "ADDITION OF VALUES" << c;
return 0;
}
IN THE TERMINAL WINDOW IT SHOWS.
ENTER VALUE OF A==5 ( WHEN I PRESS ENTER )
THEN IT SHOWS
PS C:\User\Owner\Desktop\C-C++>5
5
AGAIN
PS C:\User\Owner\Desktop\C-C++>
PLEASE ANSWER THIS PROBLEM :(
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.
I'm trying to write a simple c++ program that takes a number of miles as input and returns a conversion to kilometers. Here is my kilo.cpp:
#include <iostream>
using namespace std;
int main()
{
double miles;
double km_to_mile = 1.609;
cout << "Please enter number of miles: ";
cin >> miles;
miles *= km_to_mile;
cout << "That is " << miles << " kilometers.";
}
The program compiles, but when I run it it crashes when it tries to output the double. The last line I get in console is "That is " and I get the Windows error message "kilo.exe has stopped working."
I've tried a few other code samples and whenever I try to use cout to output a double value, the program crashes with the same error. I assume this is some problem with my compiler (mingw on Windows 8.1), but I've tried reinstalling the compiler a few times now to no avail.
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.
I want to execute in Code::blocks IDE program providing standard input.
Say
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a;
double b;
cout << "Side one\n";
cin >> a;
cout << "Side two\n";
cin >> b;
cout << "Result :" << sqrt(a*a + b*b) << endl;
}
With arguments "a" and "b" , provided in file:
Say:
2 4
I could do that in bash, compiling and then:
"./my_compiled_program < ./myinput"
I simply want to have, file with argument (standard input) in code::blocks.
How can I do this?
PS: The "set program's arguments" unfortunately don't works
Thanks to #aleguna:
We should make file in folder where is the file we want to compile and execute:
And then add the < ./input to program arguments, where input is the name of file we placed next to source code.
Thank you #aleguna.