|
Same suggestion again. You need simply to count the length of the string and put that many spaces between the two characters. I'd do the whole lot in one function, to be honest.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I am trying to develop a prototype that will display text the following way:
Help Me!
e e
l M
p
p
M l
e e
! H
Help Me!
Can anyone provide any suggestions? I beleive that a prototype names such as ShowTop, ShowSides and ShowBottom would work, but I just can't figure the logic for sides.
Thanks,
Brad
"If you fell sad about your life, just go to the mall"
|
|
|
|
|
You need to do the sides line by line, as that is how the system prints them. Then you need to take the string in question, and set up two variables, one to index front to back, the other to index back to front. Then keep adding to one, subtracting from the other, and outputing lines.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Thanks. The text was actually supposed to be a square box. Opps!
Tx.
Brad
"If you fell sad about your life, just go to the mall"
|
|
|
|
|
does any one know how to read in a file using visual C++?
like if you don't want to input everything from the keyboard
. and you already have your file saved somewhere
thanks
|
|
|
|
|
Yes, you can use IOStreams. Create a ifilestream, and it will read from the file using the same sort of code you've been using to read the keyboard.
ifstream file("c:\file.txt");
if (!file.isgood())
{
cout << "Failed to open file\n";
return;
}
char name[20];
int number = 0;
file >> name >> number;
This assumes you know the format you are reading in ( i.e. what is a string and how long it is, what is an int, etc. ), but I know in your case this is true. Check my previous posts for an easier way to read in a file into an array, but it's no good to you right now, because it uses STL, etc., which I know you're not allowed to do right now.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
i don't think i explained my problem very well. here is the deal:
I want to start debugging my code, so i did as you said i pressed F9
to set my break points, then i pressed F5.
when the program started running it a small DOS window popped on the screen asking me for input.
ok now i cannot enter all the input from the keyboard because it's abig file
;
do you know how to redirect it to go read from that file
instead of the keyboard?
thank you
|
|
|
|
|
My answer remains the same - if you use an ifstream instead of cin, you can leave the rest of your code the same and it will read from the file instead of the keyboard. Isn't that what you want it to do ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
i don't think i explained my problem very well. here is the deal:
I want to start debugging my code, so i did as you said i pressed F9
to set my break points, then i pressed F5.
when the program started running it a small DOS window popped on the screen asking me for input.
ok now i cannot enter all the input from the keyboard because it's abig file
;
do you know how to redirect it to go read from that file
instead of the keyboard?
thank you
|
|
|
|
|
Project settings->Debug->Program arguments:
<< name_of_your_file
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
are arrays passed by reference or copy
if they are passed by copy, can you tell me how would you pass an array of char by reference?
thank you
|
|
|
|
|
Are you talking about this?
char szArray [10];
MyFunction (szArray);
In arrays like this, it passes the array by the pointer to the start of an array.
Now, if you are talking about STL arrays such as....
int MyFunction (std::vector <int> &vArray)
{
...
}
main ()
{
std::vector <int> v;
MyFunction (v);
}
Now if you leave off the "&" symbol in the function definition, it will pass the array by making a copy. The "&" will cause it to be passed by reference.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Hi,
Imagine you have two classes with the following headers:
//***************** Class CFirstClass ****************
#include "SecondClass.h"
class CFirstClass
{
public:
CFirstClass();
virtual ~CFirstClass();
CSecondClass* pointer;
};
//***************** Class CSecondClass ****************
#include "FirstClass.h"
class CSecondClass
{
public:
CSecondClass();
virtual ~CSecondClass();
CFirstClass* pointer;
};
We have a situation of a circular reference and I don't know to handle that problem. I tried with a forwarding instead of '#include "SecondClass.h"', but I get the error: 'use of undefined type 'CSecondClass'' !!!
My concret problem is much more complex but I think I can summarize it with the above description. Does someone know how to solve this easily? (without building the second class into the first one)
Thanks for your help
|
|
|
|
|
Ok, the simple solution is that you can add.
class CSecondClass;
To the start of FirstClass.h. This will at least allow you to specify pointers or references to the class in CFirstClass. However, you won't actually be able to do any operations on them.
If you have to do operations on the classes, then you will have to remove the inline routines from the class definition.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Thanks Tim,
I already tried the forwarding with 'class CSecondClass', but since I need to do some operations on the pointers, I get the error 'use of undefined type 'CSecondClass''.
I don't use the keyword 'inline' at all and I don't put any function body in the header file. What is wrong??
|
|
|
|
|
Even though the compiler doesn't have to generate code when it parses that inline function, it still has to have the class definied in order to parse the function.
I have always had to move the offending inline functions out of the class definition and place them in the CPP file or in an .inl file that is included after both class definitions have been included.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
It's working now, thanks
Best regards
|
|
|
|
|
I forgot to say thank YOU
so THANKS
|
|
|
|
|
First, try using a debugger, it really makes finding bugs a LOT easier.
Next, check the code:
else
mi = mi;
When you get a match, lo and hi are not getting changed and thus you test the same index over and over again. Instead of "mi=mi", you should have a break statement there to get you out of the loop.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
class A{
public:
int m_var;
A(){
m_var=0;
};
}
class B{
public:
A m_var2; //I want to know where the class A's struct function can be execute? thanks!
}
|
|
|
|
|
The constructor is called before B's constructor, so if it took an argument, you could not do this:
class A{
public:
A(int n){ m_n = n;};
etc.....
class B{
public:
A m_var2;
A()
{
m_var2(7);
}
You'd need to do this in your cpp file:
A::A() : m_var2(7)
{
}
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
the Server end send 3 times, while one recv in Client CAsyncSocket will get all 3 packets, why?
one is the other who absorbs the thoughts of others
|
|
|
|
|
Sounds like you are using UDP. Since UDP is packet based instead of stream like TCP, a recv will return only 1 packet at a time.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
no, i am using TCP
the snippet is here
BOOL bOK=pSock->Create();
if(bOK)
{
pSock->AsyncSelect(FD_READ | FD_WRITE | FD_CLOSE | FD_CONNECT | FD_OOB);
retcode=pSock->Connect(m_host,m_port) ;
one is the other who absorbs the thoughts of others
|
|
|
|
|
TCP is a stream based protocol, there's no relation between the number of send() calls at one end of connection and recv() calls at the other end. The network is free to split or merge "packets" as long as all bytes get transmitted and the ordering stays correct.
|
|
|
|