Author Topic: Seemingly empty .cpp file?  (Read 1838 times)

Offline Firana

  • Single posting newcomer
  • *
  • Posts: 1
Seemingly empty .cpp file?
« on: January 19, 2024, 07:57:11 pm »
I have a ~2kb .cpp file I created in CodeBlocks on a different computer (that I don't have access to anymore), with some code that compiles and runs no problem. However, whenever I try to open it in CodeBlocks on my own computer, it looks as-if it's completely empty. It's not - it still compiles and runs on this device (though the result is somewhat different from what it should be), and I can still see the code when I open it with Notepad++.

I suspect the issue might be related to language encoding, as that code contains quite a few characters specific to central/eastern European languages (that part is non-negotiable as it is a part of my assignment to deal with various encodings, I cannot simply remove them). Whenever I open the file on my own computer in Notepad++, instead of the specific characters I put in, I see scrambled garbage (it was fine on the other computer).

I tried opening the file in Notepad++, changing its encoding, and copying the code into a new empty CodeBlocks file, but then I get this error:
error: narrowing conversion of '50309' from 'int' to 'char' inside { } [-Wnarrowing]|

Which I'd guess could be due to the character being interpreted as encoded in UTF-8 or something...? I don't know what's happening.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7594
    • My Best Post
Re: Seemingly empty .cpp file?
« Reply #1 on: January 19, 2024, 08:04:58 pm »
Do you save it as unicode? If not try that.
Edit: Note copy and pasting is not as good as file save as with new encoding and new filename.

If yes, then post the build log and the first line of code with the error.
NOTE: Posting code is often against the rules but, I think none will complain about one line of code.

Tim S.
« Last Edit: January 19, 2024, 08:07:04 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
When in doubt, read the CB WiKi FAQ.

Offline nenin

  • Almost regular
  • **
  • Posts: 214
Re: Seemingly empty .cpp file?
« Reply #2 on: January 20, 2024, 07:42:25 am »
Do you save it as unicode? If not try that.
I can confirm issue. It is rare (I faced it 2-3 times last 2 years). I suppose it is corrupted unicode  issue. I solved it by copy-paste code from notepad++ to C::B. I suspect that these problematic files  were generated by some early nightly builds of C::B64.

Offline Grit Clef

  • Multiple posting newcomer
  • *
  • Posts: 62
  • Where there is a will, there is a way.
Re: Seemingly empty .cpp file?
« Reply #3 on: January 20, 2024, 11:22:02 am »
I'd met this problem in the past,  too. It maybe isn't completely  related to CodeBlocks, in my case. Often it's occurred when you switch between different editors. I had solved them in the similar way to nenin's, and by chance.
-Windows 7, 32-bit
-CodeBlocks r13518, gcc 13.2.0, debug version