ofstream - overwrite a text in a file using c++ -


मुझे निम्न कोड में एक समस्या है:

  fstream s ("tst.txt ", Fstream :: बाइनरी); S.seekp (5, एफस्ट्रीम :: बेख); S.write ("परीक्षण", 7);   

इसे फ़ाइल में पहले पांच वर्ण रखना चाहिए, जैसा कि यह है, लेकिन ऐसा नहीं है! यह पूरे पुराने डेटा को त्यागने के लिए, मुझे पुराने डेटा को रखना होगा और फ़ाइल डेटा का सिर्फ एक ब्लॉक अधिलेखित करना होगा, और यह किसी भी एक बाइनरी मोड में होना चाहिए? अग्रिम में धन्यवाद।

इसे आज़माएं:

  fstream s (" Tst.txt ", fstream :: binary | fstream :: in | fstream :: out); S.seekp (5, std :: fstream :: beg); S.write ("परीक्षण", 7);   

एक ओपनमोडा ध्वज निर्दिष्ट करके, आप अपने एफस्ट्र्रीम कन्स्ट्रक्टर कॉल में डिफ़ॉल्ट ओपनमोलोड को ओवरराइड कर रहे हैं।

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -