Trouble moving code from CodeBlocks to Eclipse [message #1821182] |
Thu, 06 February 2020 17:05 |
Zyphen Visuals Messages: 1 Registered: February 2020 |
Junior Member |
|
|
Im a newcomer to both eclipse and programming, as i've only recently started programing classes in school. Yesterday, i created this code in CodeBlocks, and it seems to be running fine, but after copying it to eclipse, the process stops with and error. For the input.in and output.out files, i went to new file and made them from there, which automatically added them to the source folder, or so it seems. I don't really understand why it would work in one IDE, but not the other.
(Also, other programs do work in Eclipse. I did set up the mingw, etc)
#include <iostream>
#include <fstream>
using namespace std;
long long v[1000000];
ifstream fin("input.in");
ofstream fout("output.out");
int main()
{
long long k, l=2, i=0, x;
long long s=0;
fin >> k;
k=(k*(k+1))/2;
while(i<k)
{
if(v[l]==0)
{
s=s+l;
for(long long j=2*l; j<1000000; j+=l)
{
v[j]=1;
}
i++;
}
l++;
}
fout << s;
return 0;
}
|
|
|
Re: Trouble moving code from CodeBlocks to Eclipse [message #1821440 is a reply to message #1821182] |
Thu, 13 February 2020 04:58 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
You're going to have to be more explicit.
What do you mean by "not working"? "Doesn't Work" could mean anything.
Did you get and error message? What was the error you got?
You are attempting to read a file from the current working directory.
When running from Eclipse that usually would be the current project directory.
You said you placed "input.in" in the src directory which is a subdirectory to the project directory.
Just as a side note, it's good practice to do error checking in your programs.
You could test that the file was opened by fin with
if (fin) {
// then it opened OK
} else {
// some problem during open of "input.in"
}
Read more here: https://stackoverflow.com/questions/13446593/c-ifstream-error-checking
[Updated on: Thu, 13 February 2020 06:54] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04776 seconds