|
which input file is the one is should be checking.This code compile and its continueing looping...how to check the input file.
|
|
|
|
|
First of all, the condition that you are applying is wrong. Because, eof( ) is a function that returns true if current position of the file pointer is end of file. It is used when you are getting input from file. When you are copying something to file, you can not use this condition because as you copy something to file, the end of file pointer moves immediate after last charecter in file. As you are getting input from data.txt, you should modify your loop like this,
while (!fin.eof())<br />
{<br />
do something;<br />
} if you still have problem, let us know.
Good luck.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
i tried that allready..but now it dont wanna loop..onli the input from the file appears..and then..there is no output in the output file "MyFile.txt"..my code is down here...
<code>#include <ctime>
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
time_t tmStart, tmEnd;
void DoStuff()
{
tmStart = time(0);
ifstream fin("data.txt",ios::in);
ofstream File("MyFile.txt",ios::out);
char str[14];
fin.getline(str,sizeof(str),'\n');
string line(str);
cout << str<<endl;
int i=0;
while(!fin.eof() !=0)
{
random_shuffle(line.begin(), line.end());
File << "Randomised: " << line << endl;
File << " : " << line << endl;
File << " : " << line << endl;
File << " : " << line << endl;
File << " "<< endl;
// File << "Single Row: " << s << " " << s << " " << s <<" " << s << endl;
File << " "<< endl;
++i;
tmEnd = time(0);
cout << tmEnd-tmStart << " seconds " << endl;
}
File.close ();
fin.close ();
}
int main(int argc, char* argv[])
{
DoStuff();
cout << "finished"<<endl;
return 0;
}
</code>
|
|
|
|
|
You are not using my code...
I did not put !=0.
Also send us your file format of data.txt
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
now i using but still the same...
and then my data.txt is 0123456789123...
|
|
|
|
|
Oh man! check your logic. You get input from file in an array. Since you have got all the data from there, file pointer has reached to end of the file. Now when you go in loop, condition is true. So nothing will be printed in output file.
So if you want to get correct output of your code, let us know what exectly you want from your code to do in while loop.
Good luck.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
does your file contains 14 charectors only or more...
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
|
How will the "fin" file ever reach the end when you're only reading from it once! Surely you need to move the fin.getline(str,sizeof(str),'\n'); bit into the while loop.
Steve
|
|
|
|
|
In fact you should get input from data.txt within your loop. As you are not getting input in loop, your file pointer in data.txt in not moving. So there will be infinite loop.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
yeah..how can i stop the loop once i got all the possible shuffling of numbers.
|
|
|
|
|
so did you get your problem solved?
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
yeah thank u..it continues long way more...bcause i ve to end up this with GUI interface....just took a challenge to learn C++ in 2 weeks...till ca MFC part...n i m learning alot..thankz..for who r kind hearted to help!
|
|
|
|
|
makaveli_07 wrote: just took a challenge to learn C++ in 2 weeks
2 weeks... It's a joke, isn't it ?
And, if you really want to learn something, it is not by doing cut and paste without trying to understand that you will learn something. Really, if you want to learn the language, follow my advice: buy yourself a good book and start from the begining (and do the things yourself and THINK by yourself). It's not because you made a program (with the help of people here) that you can program.
Learning a programming language is like learning a new language and also a new way of thinking (if it's the first language that you learn). What will you think if I tell you that I want to learn Japanese in two weeks.
|
|
|
|
|
now everythin is okie but...onli one line of digit output in the file..i need all the possible randomized shuffling..
<code>#include <ctime>
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
time_t tmStart, tmEnd;
void DoStuff()
{
tmStart = time(0);
ifstream fin("data.txt",ios::in);
ofstream File("MyFile.txt",ios::out);
char str[14];
// fin.getline(str,sizeof(str),'\n');
// string line(str);
//cout << str<<endl;
int i=0;
// while(fin.eof() == NULL )
while(true)
{
if(fin.getline(str,sizeof(str),'\n'))
{
string line(str);
random_shuffle(line.begin(), line.end());
File << "Randomised: " << line << endl;
File << " : " << line << endl;
File << " : " << line << endl;
File << " : " << line << endl;
File << " "<< endl;
// File << "Single Row: " << s << " " << s << " " << s <<" " << s << endl;
File << " "<< endl;
++i;
//continue;
tmEnd = time(0);
cout << tmEnd-tmStart << " seconds " << endl;
}else break;
}
File.close ();
fin.close ();
}
int main(int argc, char* argv[])
{
DoStuff();
return 0;
}
</code>
|
|
|
|
|
I've been very patient and even defended you for asking so many questions in the face of other CPians suggesting that you're not even trying and that in fact all you're really trying to do is get other people to do your work for you. Was I wrong? Look how quickly you ask another question after the never ending loop problem was solved for you. It seems impossible that you’ve given the problem any serious thought.
Steve
|
|
|
|
|
Stephen Hewitt wrote: I've been very patient
That's for sure
I gave up when I posted code that he was even not capable of simply copying
|
|
|
|
|
The Microsoft Most Valuable Professional (MVP) Program recognizes and thanks outstanding members of technical communities for their community participation and willingness to help others. The program celebrates the most active community members from around the world who provide invaluable online and offline expertise that enriches the community experience and makes a difference in technical communities featuring Microsoft products.
I've been asked by Microsoft to nominate North American Visual C++ developers deserving of Microsoft MVP status. Please make your nominations here or email me at webmaster@codeproject.com.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Chris, I know you are really busy, did you consider offshoring this effort?
Sorry couldn't resist.
led mike
|
|
|
|
|
|
Trollslayer wrote: MVPD (Most Valued Prima Donna)?
Maxwell Chen
|
|
|
|
|
The problem is there's only a limited number they can take.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Did you perhaps mean VAIN -- Most Vain Prima Dona
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
I am working on a school project to find the volume of a wine goblet. Does anyone have c++ code for solids of revolution such as rotation of a curve around an axis? Something basic like a sin wave? I can then work on altering the code to find the rotated volume of my wine goblet.
Thanks in advance.
John
|
|
|
|
|
You can do this with a variant of integration. I remember doing it at uni but I forget the details. The idea is similar to integration where you find the area under a curve by subdividing it into n rectangles and adding the area of each then find the limit as n approaches infinity. With the volume of rotation of a 2D curve around the x-axis (which produces a 3D solid) you use a similar process except instead of rectangles you use discs (like coins) with the height of the curve at a given point being the radius and the thickness being the length of the interval divided by n.
Steve
|
|
|
|