i wrote my programs in visual-studio. now i have an mac and i want to program there like visual-studio. but there are differences between them. Is there any solution that i can write a code in Xcode that it is compatible in visual-Studio and works without any errors?
You can easily write portable low level code in C/C++, but any GUI code or code which calls the OS will be non-portable.
Is there any solution that i can write a code in Xcode that it is compatible in visual-Studio and works without any errors?
Write standard portable source code. Xcode uses the GCC toolchain, VS uses MS's cl compiler. They are different. Xcode does have the notion of projects and solutions and allows configurations. However, they are a bit complicated (so beware). Also, the Xcode debugger is buggy and the editor is not as feature-rich as the VS2005/VS2008 IDE.
You can build Cocoa/Carbon based applications on Xcode but these won't compile/run on VS. Similarly, you can build Win32 applications on VS which won't run/compile on Xcode.
All in all, Xcode is your best shot at an IDE if you're not a vim/emacs fan.
Java would be also a good solution for platform independency. NetBeans would be my choice.