עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

|שאלה בC++ | איך אני משרשר משתנה INT ושתי משתני STRING לSTRING אחד ?

Featured Replies

פורסם

אני צריך ליצור משתנה STRING שמכיל מספר כלשהו ושתי שמות.

נ.ב,

המספר כבר מוגדר כאינט.

תודה

פורסם


char *str1;
char* str2;
int num1;

char strnum[10];
char strnew[80];
strcpy(strnew, str1);
strcat(strnew, str2);
itoa(num1, strnum, 10);
strcat(strnew, strnum);

הסבר:

str1 ו-str2 הן 2 המחרוזות, num זה המספר. strnum זה מחרוזת זמנית לאחסון הייצוג המחרוזתי של המספר. strnew זו המחרוזת שתכיל את השרשור.

strcpy - מעתיקה את str1 לתוך strnew.

strcat - מעתיקה את str2 לסוף של strnew (=משרשרת).

itoa - ממירה מספר ל-string. מקבלת את המספר, מצביע ל-string להכניס לתוכו את התוצאה, ובסיס המספר.

זה ע"י שימוש בפונקציות של C... יכול להיות שב-C++ יש אפשרות לעשות את זה יותר בקלות, אני לא מכיר מספיק טוב את השפה..

פורסם
  • מחבר

תודה אחי! אבל אני צריך מימוש דרך הCLASS של STRING זה אמור להיות יותר פשוט בC++.

תודה

פורסם
  • מחבר

מצויין . תודה רבה :xyxthumbs:

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.