Nice one !!!
#include <iostream>
using namespace std;
class foo{
public:
foo& operator () (){
return *this;
}
};
int main(){
foo()()()()()() ()()();
getchar();
...
User Profile
Collapse
-
printf question
Hi,
Check this program.
#include <stdio.h>
int main()
{
int x = 0xFFFFFFF0;
printf("%X\n",x );
char y = x;
printf("%X\n", y);
getchar();
}
I have FFFFFFF0 in int variable x and i am assigning it to char. Since a char can hold only 8 bits, it should have only F0. But when i try to print it, it prints the entire... -
I showed this as an example. If i put this is a function which accepts an int and use that paramter in place of 1100 it will be generic.Leave a comment:
-
How about this ...
String s = "" + 1110;
int[] b = new int[4];
for(int i=0; i<s.length();i+ +) {
int d =Integer.parseI nt(""+ s.charAt(i));
b[i]=d;
}Leave a comment:
-
Private Interface example
Just thought of posting this example about private interface which i learned from bruce eckel book "Thinking in Java"
An interface can be nested within a class or another interface. If the interface is nested within a class it can be public or private. But if a interface is nested within a interface it should be public which is by rule.
I was wondering what will be the use of private interface within a class.... -
Is it because "this" is a reference to the object in java and "this" is a pointer in c++Leave a comment:
-
C++ constructor differs from java
Hi,
I was just browsing some java code and found that it is possible in java to call a constructor within another constructor. The rule being that the it should be first line in the constructor and also there shouldn't be any duplication.Bot h these rules have valid reasons. But why can't we do the same in c++.
Java Code :
public class c {
public c(){}
public c(int a){
... -
Yes you are correct. I have a InputStream and OutputStream. I know it is unfair to ask more than this. I have an inputStream which displays what happens on the remote machine i.e it shows the script running status. Any idea on how to grep for a particular statement. Just a clue on which function to use. In the mean time let me go through the API ...
Thanks for your quick reply.Leave a comment:
-
Java code for auto answer
Hi ,
I am new to java and i created a program which does an automatic SSH connection from host to a remote machine. I have created a channel from host to remote machine and i am executing certain scripts in the remote machine from the host. This has been done in java. Now the problem is when i run some scripts it prompts for Y/N type of question. I need to answer to that from host machine. Is there anyway to do this.
... -
I am sorry as i recalled now that all methods in java defaults to virtual. In C++, it needs to be done explicitly.Leave a comment:
-
Inheritance Doubt
Hi ,
I am migrating slowly from c++ to java. The output of the following program differs from c++ in java. It should be really easy for any java programmer to explain. Just an hint could help me to understand.
class base {
public void f(){
System.out.prin tln("base.f()") ;
g();
}
public void g(){
System.out.prin tln("base.g()") ;
}
}... -
vinothg started a topic How compiler diffrentiates oridnary/member funtion w.r.t private data membersin CHow compiler diffrentiates oridnary/member funtion w.r.t private data members
Hi All,
I just wanna know how compiler diffrentiates between a ordinary function and member function. I know that compiler will secretly pass the this pointer to member functions. Eg : look at this code.
[code=cpp]
#include <iostream>
using namespace std;
class A {
int i;
public :
int k;
void set(A* a, int i){
a -> i = i; >>>> Here it... -
Accessing private data members from ordinary function and member function
Guys,
I just wanna know how compiler diffrentiates between a ordinary function and member function. I know that compiler will secretly pass the this pointer to member functions. Eg : look at this code.
#include <iostream>
using namespace std;
class A {
int i;
public :
int k;
void set(A* a, int i){
a -> i = i; ... -
You have a static variable as a data member in your class.Static variables will not be initalized by the constructor.It has to be explicitly define it.
You need to add this line.
HotDogStand::To talSales = 0;
If you still have queries refer
http://www.parashift.c om/c++-faq-lite/ctors.html#faq-10.10Leave a comment:
-
Silly Pointer Problem
Hi ,
I just wanna know why such a wierd output is seen for the following program.I know it is pretty simple but i can't make it.Just a clue could help me to sort out the issue.
...Code:#include <iostream.h> #include <stdio.h> void func(char *s) { printf("%x \n",s); s="senthil"; printf("%s %x\n",s,s); } -
Read/write problem using fstream in binary mode.
I have a binary file,which contains strings of 30 bytes each.I need to open the file,read the strings one by one and if the string is not found i need to write it.But unfortunately both read and write using fstream is not not working.If i close the file and open it again it works.
...Code:#include <iostream> #include <sys/stat.h> #include <fstream> int main(){ fstream fs; -
You can use Associative array i.e STL containers for this problem.
The best container for this would be the SET container.Leave a comment:
-
Ok if you know the exact offset where you want to append then this piece of code may help you.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream os("test",ios:: out|ios::app|io s::binary);
os.seekg(20,ios ::beg);
char buffer[3] = {"Hi"}
os.write((char* )(&buffer),size of(buffer));
os.close();
}Leave a comment:
-
When you create a object for the Dlist it certainly occupies the memory.
If i recall correctly the correct procedure to avoid memory leaks when using a Dlist is :
Delete the element with a pointer list and at the end, delete all the elements and the list with clearAndDestoryLeave a comment:
-
When you open the binary file add ios::ate so that the string will get appended instead of overwriting i.e
nfile.open("new .txt",ios::in|i os::out|ios::at e|ios::binary);
Hope it will work !!!Leave a comment:
No activity results to display
Show More
Leave a comment: