Thứ Năm, 21 tháng 7, 2011

Convert std::string to int and vice versa

 You can convert std::string to int by this syntax:

std::string sNumber = "123";
int number;

number = atoi(sNumber.c_str());

To convert int to std::string, you can convert int to char*, after that you can convert char* to std::string
To convert int to char*, you can be able to use this syntax


char str[10];
itoa(number,str,10);  // 10 --> convert to 10 base

Thứ Ba, 19 tháng 7, 2011

Get all file's name and subdirectory from directory 's path

If you want to get all file's name from folder's path in C++, you can use many way. I know one way which can help you to do this work.
There are some steps you have to do:
+ The first, you must add chain: "\\*.*" after your path.
+ The second, calling FindFirstFileA function to find the first file in your folder
+ Then you calling FindNextFileA function to find all file to the end
And this is my source code that you can use:

   // You have to use windows.h and tchar.h library

    char * pathFolder = "D:";
    char* FileNext;
    WIN32_FIND_DATAA  findFile;
    HANDLE hfind;
    char folderFind[255];
    int isFinish;

   sprintf(folderFind,"%s\\*.*",pathFolder);
    hfind = FindFirstFileA(folderFind,&findFile);
    isFinish = FindNextFileA(hfind,&findFile);     


    while(isFinish)
    {
        FileNext = findFile.cFileName;                      // Do with your file's name
        isFinish = FindNextFileA(hfind,&findFile);  
    }

Best wishes for you. Thanks for visting my blog!
Do your best, the rest will come!

Convert CString to std::wstring

To convert CString to std::wstring in MFC or C++, you can use this syntax:
 
   CString myCString = "I love Viet Nam";  // If you use Unicode format, you have to insert 'L' character before this quote
   std::wstring result;
    result = (LPCTSTR)outPutFolder;

We look it is same as the way that we use to convert CString to std::string when we don't use Unicode format.
Best wishes for you. Thanks for visiting my blog!
Do your best, the rest will come!

Thứ Bảy, 16 tháng 7, 2011

A good site for CString

Today i surf web and i find an good website for CString data. It has a lot of information about CString so i can't read all of it. I want to introduce to you so that we can read together and we can read faster and faster.
This is the link of the website that i found:
http://www.flounder.com/cstring.htm#Converting%20between%20char%20*%20and%20CString

I hope you will join me. Thanks a lot!
Do your best, the rest will come!

Convert CString to char* and vice versa in MFC

 Hi everybody,I am Cuong, i come from VietNam. I have just said about some topic recently. Today i want to return "convert" topic to introduce to you how to convert CString to char* and vice versa in MFC.
Do you know about it ? And is it easy?
When i had a project some months ago, i had to use it but i didn't know and i felt that it was really difficult. But now i feel it is easy because i found one of the best way to do it.
For saving your time, i am introducing now.

+ Convert CString to char*

   CString myCString = "I love Viet Nam"; // using: L"I love Viet Nam" if you want to do with Unicode format
    char myChar[1000];  // the number depends on your CString's length
    //initialize your storage buffer
    memset(myChar,0,sizeof(myChar));
    sprintf(myChar,"%S",myCString);

Actually, you can use an easier syntax if you don't use Unicode format
   myChar = myCString.GetBuffer(myCString.GetLength());

+ Convert char* to CString

  CString myCString;
  char* myChar = "I love Viet Nam"; // You mustn't insert  'L' before this quote although you can use Unicode format
  for(int i = 0; myChar[i] != NULL; i++)
  {
         myCString += myChar[i];
  }
 
Maybe there are many ways to convert this type but i think this is an easy way that you can use.
Best wishes for you!, Thanks for visiting my blog!
Do your best, the rest will come!

How can you create "Browse" button in MFC's application

Have you ever created a MFC project that you must have had "Browse" button?
How could you do it?
I have done many projects in MFC and i have some experiment about this topic.
Today i am here to say to you the way you can create a "Browse" button in MFC application.
I suppose that your application's name is DemoBrowse so there are two choice for you.
If you want to browse only one file, you can drag an button object, after that you can write it's source as:
void  CDemoBrowseDlg::OnBnClickedButtonBrowse()
{
        CFileDialog FileDialog(TRUE, 
                                               "*.*", 
                                               NULL,
                       OFN_HIDEREADONLY,
                       "All files:(*.*)|*.*|       // If you want to chose all kinds of file
                       Files .txt (*.txt)|*.txt|  // If you only want to chose .txt file
                       Files word    (*.doc;*.docx)|*.doc;*.docx||"); // If you want to chose .doc and .docx file
        if (FileDialog.DoModal() == IDOK)
        {
                   CString pathName = FileDialog.GetPathName();
                   // And now you can do anything with this path
        }

}

If you want to get lots of files at the same time, you can use this source:

void CDemoBrowseDlg::OnBnClickedButtonBrowse()
{
    int i = 0;
    CString arrayListFile[100];  // CString array which contains paths
    UpdateData(TRUE);
    CFileDialog FileDialog(TRUE,
                                            "*.*",NULL,OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,
                                             "Image Files (*.jpg;*.bmp;*.png;*.gif;*.ico;*.pbm;*.tif;*.pgm;*.xpm)|
                                            *.jpg;*.bmp;*.png;*.gif;*.ico;*.pbm;*.tif;*.pgm;*.xpm|
                                           Files(*.txt;*.docx)|*.txt;*.docx||");

     // Create buffer for ten filenames
    TCHAR strFiles[MAX_PATH * 100] = "";
    FileDialog.m_ofn.lpstrFile = strFiles;
    FileDialog.m_ofn.nMaxFile  = sizeof(strFiles); 
    // If it has err here, you can use a number ( > 0) to replace sizeof(strFiles). I haven't also known why it has err
    if(FileDialog.DoModal() == IDOK)
    {
        POSITION pos = FileDialog.GetStartPosition();
        if(pos)
        {
            CString PathName;
             do
            {
                PathName = FileDialog.GetNextPathName(pos);
                arrayListFile[i] = PathName;
                i++;
            } while(pos);
        }
        // And now you can do anything with your paths
    }

If you use Unicode format in your application, you have to insert "L" character before every quote.
Example: "*.*"  -->  L"*.*"
So you can create easily a "Browse" button by yourself.
Best wishes for you. Thanks for your attention!
Do your best, the rest will come!

Install Kubernetes using kubeadm with two nodes master & worker

Well come back for a long time my friends! Today I want to take a note about some basic knowledge about Kubernetes. I hope that it will...