I have got this from help :-
NSString *str = [[NSProcessInfo processInfo] operatingSystemVersionString];
But i am not able to use it properly.
I am working with C++ source code
That's because you can't utilize the Cocoa frameworks directly from C++.
There are a few ways to approach this; which one is best depends upon the specifics of your needs. Since you haven't provided any details about why you are trying to do this in C++, I'll take a wild guess that yours is a cross-platform app that doesn't depend upon a GUI front end but which does need OS version information for some reason.
You can access Cocoa framework classes from an Objective-C++ file (i.e., a C++ file with the extension ".mm"). Assuming that redefining the top level of your C++ application as an Objective-C++ file is not an option (which it wouldn't be for a cross-platform app), one approach would be to create a separate Objective-C++ file to do the work, as in the following (very rough) example code:
Code:
main.cpp:
#include "MyCocoaBridge.h";
int main (int argc, char * const argv[])
{
getVersion();
return 0;
}
---------------------------------
MyCocoaBridge.h:
void getVersion(void);
---------------------------------
MyCocoaBridge.mm:
#import <Foundation/Foundation.h>
#include <iostream>
void getVersion(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
std::cout << [version UTF8String] << "\n";
[pool drain];
return;
}
In a cross-platform app you would of course also have to work out your projects and calls in such a way to replace the .mm file with something else in builds for non-Cocoa environments. And don't forget to add the Foundation framework to your Xcode project.
I hope this helps to put you on a workable track.