|
i need help on chngin for loop in this file to while loop..plz solve this for me as soon as possible...i trien in many ways but cant...
#include <ctime> <br />
#include <iostream><br />
#include <string><br />
#include <algorithm><br />
#include <fstream><br />
using namespace std;<br />
<br />
time_t tmStart, tmEnd;<br />
<br />
<br />
<br />
void DoStuff()<br />
{<br />
tmStart = time(0);<br />
ifstream fin;<br />
fin.open("data.txt",ios::in);<br />
<br />
ofstream File("MyFile.txt",ios::out);<br />
<br />
<br />
char str[14];<br />
<br />
fin.getline(str,sizeof(str),'\n');<br />
<br />
<br />
string line(str);<br />
cout << str<<endl;<br />
<br />
<br />
<br />
for (int i=0; i<5000; ++i)<br />
{<br />
random_shuffle(line.begin(), line.end());<br />
File << "Randomised: " << line << endl;<br />
File << " : " << line << endl;<br />
File << " : " << line << endl;<br />
File << " : " << line << endl;<br />
File << " "<< endl;<br />
<br />
File << " "<< endl;<br />
<br />
<br />
<br />
tmEnd = time(0);<br />
cout << tmEnd-tmStart << " seconds (that was fast!)" << endl;<br />
<br />
} <br />
File.close ();<br />
fin.close ();<br />
<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
DoStuff();<br />
<br />
return 0;<br />
<br />
}<br />
<br />
<br />
|
|
|
|
|
Mmmmh... At first glance, this is not even easy, it is trivial... smells like homework ... please post your code that does not work with your while attempt, and we will help you.
~RaGE();
|
|
|
|
|
i know its sumthing about this but i dont knw how to implement it..
{<br />
char str[2000];<br />
fstream file_op("c:\\test_file.txt",ios::in);<br />
while(!file_op.eof()) <br />
{<br />
file_op.getline(str,2000);<br />
cout <<str;<br />
} file_op.close();<br />
cout <<endl;<br />
<br />
|
|
|
|
|
Please, stop asking things you don't even understand. Take a C++ book and start reading it.
How will you learn if people make the complete program for you (this is what is happening right now, looking at the number of questions you already asked for such a trivial code snippet).
|
|
|
|
|
i am learning...give me any hint on this...
|
|
|
|
|
|
A good book. Every C++ programmer should read it.
Steve
|
|
|
|
|
|
I started reading it after already "knowing" C++: I thought I wouldn't learn much from it: I was wrong.
Steve
|
|
|
|
|
Stephen Hewitt wrote: I thought I wouldn't learn much from it: I was wrong.
Such as? Do you mind listing a few which you learned in addition from the book? Thanks.
Maxwell Chen
|
|
|
|
|
The main thing learnt from the book is to program in C++ in such a way that makes use of the language’s features in a natural manner. One of the major problems with many C++ programmers in my opinion (and the book's) is that they use C++, for the most part, as if it was simply a better C. It emphasizes the standard library and the STL. In also clarified a lot of language subtleties such as the fact that enum s have a range, for example. It explains a lot of things like which statements are portable, which result in implementation defined beaviour and which result in undefined behaviour (and the distinction between them). It explains the difference between C and C++. It is a good reference manual. It explains programming techniques as well as language and library issues. It also goes into problems such as how to manage a large software project. It's hard to list all the things you learnt from a book like this off the top of your head. My advice to any C++ programmer (and to employers) is to treat it as required reading.
Steve
|
|
|
|
|
Thank you for the comments.
I found some people (not too many) in CP who are good in STL during my 4-year membership, and you are among them. Thus I'm interested and I would like to hear your comment to Stroustrup's book.
I read those various readers' reviews on this book at Amazon site several years ago. Some said it a very good book, whereas the other felt it in poor writing skill.
For myself, my English wasn't really good but just so so when I bought this book in Nov 1998, the 1st time I started to learn programming from knowing nothing. So I spent 3 months go through another book first, "C++ from the ground up", which is in pretty plain English. Later I read Stroustrup's.
Personally I feel there two cons with this book:
1) Not really fits for newbies. The pace goes too fast from the basic.
2) Link references too often. That is: .... (refer to $2.5.3), ..... (refer to $3.1.1), ... It is apprehensible because he was trying to elaborate that much things in one book.
Except the above, it is really a very good book to me.
Maxwell Chen
|
|
|
|
|
so why didn't you tell me about this book before
i've been posting question's for quite some time in this forum
I'm a newbie and i asked if you know a good c++ reference book or site
many times. So do you recomend this book. Will i learn as much as you if i read it ?
|
|
|
|
|
Cedric Moonen wrote: Please, stop asking things you don't even understand.
Why would he ask questions about something he understands?
Steve
|
|
|
|
|
Sorry, what I meant is that he even doesn't try to understand the answer. The only thing he's interested in is having the solution without too much effort. Take a lot at all his other thread (this one[^] for example).
I mean, we don't help him providing all the code for him. He needs to learn things by himself, take a good book and start from the begining.
I didn't say that to be mean but how will you learn to program when all you do is cut and paste code that people give you and then asking question why you get compile errors (without even trying to correct them yourself).
|
|
|
|
|
I take your point. The example you cited was interesting: it was based on some code I submitted but changed around a little. My point is that it looks like he's trying. I don't want to do someone’s homework (if that's what it is), but at the same time I remember what it's like to be a beginner: almost anything you read to help you soon refers to a concept you don't know or understand and it's very hard to get started.
Steve
|
|
|
|
|
makaveli_07 wrote: char str[14];
//cout << "sr"<<endl;
fin.getline(str,sizeof(str),'\n');< blockquote="">
Don't do stuff like this. Here's a rule of thumb: Forget about char arrays, use std::string s instead. i.e.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream ifs("C:\\a.txt");
if (ifs)
{
unsigned int line = 1;
string s;
while (getline(ifs, s))
{
cout << "Line " << line++ << ": " << s << endl;
}
}
return 0;
}
Unless you're optimising code or have some other compelling reason don't get user input in char arrays.
Steve
|
|
|
|
|
in a general manner :
for (init_statement; condition; increment_statement) {
instructions;
}
init_statement;
while (condition) {
instructions;
increment_statement;
};
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
makaveli_07 wrote: i trien in many ways but cant...
Show what you've tried and we can certainly critique.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
IS IT POSSIBLE TO HANDLE MOUSE SCROLL EVENT when the focus is on the LISTBOX.
When ListBox has only the Horizontal scrollbar,the MOUSE SCROLL Event is by default
linked to the HORZIONTAL SCROLL movement.
Is there any way to HANDLE this behaviour?
Is there any way to STOP this behaviour?
Can any one clarify?
UNABLE TO HANDLE WM_MOUSEWHEEL WHEN THE FOCUS is on the LISTBOX.
for thendral
|
|
|
|
|
Yes
use " mouse_event(MOUSEEVENTF_WHEEL,0,0,x,GetMessageExtraInfo()); "
and x is how much do you want weel to move .
also you can see mouse_event in help .
hope to be useful
|
|
|
|
|
Yes, subclass the listbox and handle the mouse messages yourself.
Steve
|
|
|
|
|
I wonder if it is possible to set breakpoint on something like kernel32!CreateFileA in WinDbg. When I try to execute this command:
bp kernel32!CreateFileA
I get this error message:
Type information missing error for CreateFileA
*************************************************************************
*** ***
*** ***
*** Your debugger is not using the correct symbols ***
*** ***
*** In order for this command to work properly, your symbol path ***
*** must point to .pdb files that have full type information. ***
*** ***
*** Certain .pdb files (such as the public OS symbols) do not ***
*** contain the required information. Contact the group that ***
*** provided you with these symbols if you need this command to ***
*** work. ***
*** ***
*** Type referenced: kernel32!CreateFileA ***
*** ***
*************************************************************************
Type conflict error at '<eol>'
Symbol server path is setup correctly and symbols are loaded.
|
|
|
|
|
You have to install the symbols which you can find in Microsoft WinDbg site.
Maxwell Chen
|
|
|
|
|
Thank you for your reply. Symbols from MS sysmbol server are installed and loaded.
|
|
|
|