Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Trouble moving code from CodeBlocks to Eclipse
Trouble moving code from CodeBlocks to Eclipse [message #1821182] Thu, 06 February 2020 17:05 Go to next message
Zyphen Visuals is currently offline Zyphen VisualsFriend
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 Go to previous messageGo to next message
David VavraFriend
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

Re: Trouble moving code from CodeBlocks to Eclipse [message #1821626 is a reply to message #1821440] Mon, 17 February 2020 17:01 Go to previous message
Helen Keller is currently offline Helen KellerFriend
Messages: 173
Registered: June 2019
Senior Member
Not sure how you physically "..but after copying it to eclipse.." ,but do not like your comment about " copying to source " .
Prefer not to dwell on how you did it , here is my suggestion.
In Eclipse - create plain, default "Hello world" project of your choice.
Then copy contents of your main Qt file into Eclipse main file - just the contents.
Plain text to text copy.
Add / correct necessary #includes etc. , build the new project and watch for smoke.

Previous Topic:Mac SDL2
Next Topic:Lib symbols could not be resolved
Goto Forum:
  


Current Time: Thu Mar 28 16:20:40 GMT 2024

Powered by FUDForum. Page generated in 0.04776 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top