|
I've always wanted to say that, I heard it so often in college. Now that I'm a college teacher, I can.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
Roger Wright wrote:
I've always wanted to say that
Yeah i know what you mean , never miss a change when you want to do it.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hello everyone:
How to get system time to micro second?
Thank you.
-Freehawk
|
|
|
|
|
Using QueryPerformanceCounter, see article in recent MSDN magazine:
http://msdn.microsoft.com/msdnmag/issues/04/03/HighResolutionTimer/default.aspx
Edward
|
|
|
|
|
Thank you very much for the fast reply.
-Freehawk
|
|
|
|
|
Hello everyone, i was wondering how to copy from one string to another.
for example.
I am reading a line from a file, lets say
1234 Jack
I want to parse the 1234 to temp and Jack to temp2
between 1234 and Jack is a space.
I have tried using the find and the replace function of string, but have not succeded, if anyone could help me out, it
none
|
|
|
|
|
Perhaps you could explain what the problem is and show us your code ? You want to find the index of the space, and then create two new strings, from memory CString has Left(), Mid() and Right() functions to do that.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Well here is what i am trying to do..
As you can see, i am reading from a file and putting it into buff. At first run of the look buff has
1234 Jack
what i want to do is put 1234 into temp and Jack into temp2.
CString temp,temp2
temp = "";
temp2 = "";
while( !m_sfile.eof() ) {
m_sfile.getline( buff, 256 );
}
none
|
|
|
|
|
Try this instead:
std::string name;
int number;
while( !m_sfile.eof() )
{
m_sFile >> number;
m_sFile >> name;
}
This will do it. Plus it does not taint the standard library with CString. It's much neater than string mashing.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I does not work, i get an error.
C:\TIME TRACKER\TimeTracker\TimeTrackerDlg.cpp(283) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >' (or there is no a
none
|
|
|
|
|
The std::string cannot be read from stream via >> , because the stream doesn't know, where should be the end of the string. std::istream haven't any parse capabilities (except of simple getline , that isn't useful in your case).
Try Tokenizer class at Codeproject.
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Hello,
I am not to experienced with VC++. I would like to write a program that is pretty large. (at least for me) I am having trouble with getting all my ideas on paper or in a plan of something. Any suggestions on a possible (free?) program that I can use to plan a project?
Slaru
|
|
|
|
|
Start with implementing a scientific calculator.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
If you're into Object Oriented programming, you might want to try UML. It's helpful for breaking large ideas into smaller chunks.
There are a number of UML tools available. ArgoUML is pretty nice, and free, too. http://argouml.tigris.org/
|
|
|
|
|
|
i just started learning c++ so it may just be a noob question but i am haveing a problem. I am trying to make a prog that writes names and number to notepad. When i run it it write the names and number but on top of it it has a set of numbers (1245068) and that will happen everytime.
Example:
1245068
John
Doe
5678906
Jaine
Doe
23456789
That is what is on notepad. My question is what i am doing wrong to get that set of number and how to just write the first name then last name then number. If anyone could help it would be appreciated. my code is bellow.
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
int main(int argc, char* argv[])
{
int x=0, y=0;
string L_Name[100];
string F_Name[100];
int number[100];
char resp;
//Reads if there is already info in there and puts it into array
ifstream read("File.txt");
while(!read.eof())
{
read >>F_Name[x] >>L_Name[x] >>number[x];
x++;
}
read.close();
//Where the user can enter more name
do
{
cout <<"First Name: ";
cin >>F_Name[x];
cout <<"Last Name: ";
cin >>L_Name[x];
cout <<"Number: ";
cin >>number[x];
x++;
cout <<"Would you like to enter another name?(y/n)";
cin >>resp;
}
while((resp=='y')||(resp=='Y'));
y=x;
//writes the origianl names then the new name but here is where i get the
//set of numbers
ofstream write("File.txt");
for(x=0; x<y; x++)
{
write <<F_Name[x] <<endl;
write <<L_Name[x] <<endl;
write <<number[x] <<endl;
}
return 0;
}
|
|
|
|
|
Try it without the endl, if not copy declare a CString and append the name, last name and the phone number into a string and just write the string.
CString temp_string;
temp_string = "";
while.....
temp_string = F_Name[x] + " " + L_Name[x] + " " + number[x];
write<
|
|
|
|
|
OK, let's have a look.
You included iostream.h and fstream.h, you should just include iostream and fstream ( drop the h ). The .h versions are the ones created prior to the standard. I think you'll find that you'll then need to put using std::cin;, etc. for all the parts of iostreams you use. Namespaces are just one benefit of using standard headers.
You should also investigate using std::vector to hold your data, and probably put it in a struct. The first so you don't have a limit to how many items can be entered, the second to connect the three pieces of data you collect.
I dunno what your main problem is though, I'd try flushing the stream perhaps (cin.flush() from memory), or perhaps using the standard C++ headers will even solve the problem.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
ya i tryed putting it in a stuct but it would do the same thing so i just tryed it with it out
|
|
|
|
|
The struct won't solve your problem, it merely makes your design better. Add an iostream inserter/extracter and things would be really nice.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I know in c++ you could use setpercision to change the number of decimal places outputted. So how do you do it with the Cstring variable output in a dialogbox in mfc?
I have the following:
float Float_Percentage=0;
float_percentage = m_wins/m_plays;
CString PercentageConversion;
PercentageConversion.Format("%f",Float_Percentage); // convert float to str
percentvalue=PercentageConversion; // percent is of type CString
I get output like this 0.050000
How do i make it 0.05 as in just show two decimal places in a setpercision(2)?
Thanks for your help.
Win32newb
"Making (C)Windows programs worse than they already are!"
|
|
|
|
|
Use "%.2f" instead of "%f" to format the value.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
thanks for the help that worked
Win32newb
if (user=="Win32newb")
{
CWnd::Messagebox
("DUH");
}
ELSE
{
CWnd::Messagebox
("HELP WIN32NEWB");
}
"Making windows programs worse than they already are"
|
|
|
|
|
I have a SDI and I dont override the standard file open ( i.e CWinApp::OnFileOpen() ), I do however use a separate CFileDialog to open a particular type of file.
When I use the CFileDialog to open my files I set the initial directory to open from (different from the executable dir). Then when I use File->Open it uses the CWinApp::OnFileOpen and the initial directory is the last directory from my CFileDialog, I expect this.
However I used SetCurrentDirectory to reset this directory but it still uses the previous value. It also uses this value when I retart the program and choose file->open.
How can I set this to always open in the executable directory for file->open. I dont want to override the OnFileOpen and use a CFileDialog.
---
|
|
|
|
|
Here's my code
int ParsePacket(BYTE *aPacket,short int iStartPos);<br />
<br />
<br />
void main()<br />
{<br />
BYTE aPacket[] = {0x59,0x89,0x59,0x59,0x23,0x59,0x59,0x59,0x89,0x59,0x00,0x54,0x65};<br />
int l = ParsePacket(aPacket,5);<br />
printf("%d\n",l<br />
system("pause");<br />
}<br />
<br />
<br />
<br />
int ParsePacket(BYTE *aPacket,short int iStartPos)<br />
{<br />
bool bFound = false;<br />
int iPos = 0;<br />
<br />
for (int i = 0;i < (sizeof(aPacket) - 1); i++)<br />
{<br />
printf("Test: %x\n",aPacket[i]);<br />
}<br />
<br />
return iPos;<br />
}
This piece of code should output twelve values ( sizeof(aPacket) = 13 ), but instead it only outputs the first three bytes of aPacket... why?
|
|
|
|