I'm trying to fix an encoding issue I'm confronted with when using Sublime Text.
If I try to open a c++ file in sublime it displays the file's content as a series of hexadecimal numbers. I've tried to fix this by reopening it with all the various given encoding options ("File --> Reopen with Encoding"). I have also tried the following: "enable_hexadecimal_encoding": false under settings.
Is there something else I can do to fix this problem?
Screenshot when initially opened
Screenshot after reopening with UTF-8 encoding
I think you have opened an object file(.o) with the wrong extension, I have checked it on my machine your file is originally an object file with possibly wrong extension. Read more about object files here.
Try to find the original source file, a c++ source file will have an extension of .cpp(most likely).
Related
I got a Visual Studio Qt/C++ project (from China, not sure if this matters so mentioning here because Chinese characters are a little tricky sometimes). When I open it on QtCreator (my preferred IDE) on macOS (my preferred OS) then I get
Could not decode main.cpp with UTF-8 ecoding. Editing not possible.
If I click Select Encoding and choose System then I can edit normally. I can even save and close the file but when I open it again same thing happen.
I noticed there are some comments appearing as )//?????????????????? and //???????�??????????UI which seems to be a problem related to enconding.
How to deal with this issue?
What the System encoding means?
Openning the file on SublimeText and Save with Encoding UTF8 seems to solve the problem. But I have a lot of files, any suggestion on how to do it from command line for all files?
And the file seems not to be UTF8:
$ file main.cpp
main.cpp: c program text, ISO-8859 text
Finally I went to QtCreator, Tools, Options, Text Editor, Behavior, File Encodings and set Default Encoding to ISO-8859-1. Now there is no more complains on QtCretor side. Are there any downsides on doing this?
I suspect it contains non-valid UTF-8 characters. Here is a question with the same problem on Qt forum. One of the comments says
I just discovered this because a header file from FTDI contained a copyright symbol. I just converted that to read (C) instead of the copyright symbol and it was fine.
You can try that. If it's not that, I advise you to check if it is valid UTF-8 text. You can check if it is valid UTF-8 with a command like: iconv -f UTF-8 your_file > /dev/null; echo $?, it will return 0 if it is valid and 1 if it is not valid.
I am setting my systems for codecommit. but getting following error
I followed the below link :
https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-windows.html
/c/Users/Prasanna/.ssh/config: line 1: Bad configuration option: \377\376h
/c/Users/Prasanna/.ssh/config: terminating, 1 bad configuration options
here is the config file
Host git-codecommit.*.amazonaws.com
User ********
IdentityFile ~/.ssh/codecommit_rsa
Am I missing anything to configure ?
You probably have some illegal characters in the config file. I had this problem while creating a config file on Windows. Unfortunately, simply opening the file in a Windows text editor may not show the illegal characters.
I was able to find this problem by running cat filename from a Bash prompt in Windows (git bash) and was able to fix it by running dos2unix filename in git bash. The same may work for you as well.
Just had the same issue. Open the file with Notepad++. On the bottom right it tells you the encoding the file is in. It has to be UTF-8 without BOM. You can fix that via selecting a new encoding at the top and saving the file.
This happened to me today, and I just recreated the config file and put my configs there, it works.
I have the following problem. I would like to open and save a string to file.
ofstream file("file");
file << "example" << endl;
file.close()
Rather simple stuff. The problem is... the code above doesn't seem to create any files in my project directory. I have tried to use "locate" in terminal to find my file - withoud any results. What is interesting - I can open the file using ifstream and read from it, without any particular problems.
What the heck is going on here? Where should I look for the file created?
P.S. On Windows everything works 100% fine.
in my project directory
Where did you read that this is where to look? We should collaborate and correct that resource.
I have tried to use locate in terminal
It probably hasn't been indexed yet.
You need to look in the current working directory of the terminal that started the program.
What I'm trying to do is basically:
./myProgram < myData.txt
While I'm debugging with CLion IDE. I just can't find the option to do so.
A similar question - but product-specific to MSVS
I had the same problem and it seems that CLion is not handling standard inputs yet.
I got around this problem by changing the input stream before running my program.
As an example if you want to input a file stream inside your stdin you can write in your main:
std::ifstream in("ABSOLUTE_PATH_TO_YOUR_FILE");
std::cin.rdbuf(in.rdbuf());
Then you can find a way to toggle this stream change when you want. Note that for files you will need to provide absolute path since the application is run from a different directory than the current one.
I hope this can help until CLion provides a real solution.
Assuming your input file is myData.txt, you can reopen/reuse the stdin stream using freopen
freopen("myData.txt","r",stdin);
if you want to do the same with your output:
freopen("myOutput.txt","w",stdout);
this will work for std::cin, printf, etc...
You can find more information about this here: http://www.cplusplus.com/reference/cstdio/freopen/
By the way, there is already a feature request for this. If you are interested, you can vote here so it gets prioritized:
https://youtrack.jetbrains.com/issue/CPP-3153
As of CLion 2020.1 this feature is built in:
Input redirection
If you need to redirect input from a file to the
stdin of your application, you can now do that. Use a new field in the
configuration called Redirect input from. Enter:
A relative path (CLion will prepend with the Working directory path).
An absolute path (will be remapped for remote configurations).
Or macros (like FilePrompt).
Still Clion don't have the feature like pycharm where we can give input in terminal while debugging the code.
But it has an option to give input through a .txt file while debugging.
Image of debug setting window
Click the setting icon in the debug console (on upper left corner) to open the setting of debugging. Then check the "Redirect input from" box and select the input file path and click "OK".
Here you go!
Now you can give input from the text file while debugging the code.
For me, CLion creates the executable in a file called 'cmake-build-debug'. Check out my file structure in the pic.
Then, I just opened up my terminal and went to the directory containing the executable and used this command to pipe in the text file:
./FirstProject < ../hw1.txt
So I downloaded, installed, and inserted into path the clang formatting plugin. I also tested it and it works for Google (Mozilla, etc.) formatting options out of the box, yet I cannot get it working with my .clang-format file. (I've put my file into the same folder as my source file, changed its encoding into UTF-8, also tried to put it into clang install folder, add file into project, write its contents inside '{key:value}' yet formatting does not happen). So how do you feed formatting file to chrome-format extension?
My file contents:
{ BasedOnStyle: "LLVM", IndentWidth: 4 }
My file name:nm.clang-format
Go to Tools->Options->LLVM/Clang->ClangFormat and put file in the Style option field.
Then place your style file named .clang-format (this is the full filename, not an extension) either in the source file's directory or one of its parent directories. Windows Explorer won't let you create filenames with leading . so you need to go to the console for this.
If like me you got confused later on where the .clang-format was living, use procmon to track the file reads of clang-format.exe
For the record, it seems that if both "Fallback Style" and "Style" are set to "file", no formatting will happen even if the style file is at its correct location. Setting "Fallback Style" to something different than "file" (e.g. "none") helps.
In VS2019 works if the clang-format file is named as .clang-format.
It must be .clang-format, not .clang-format.txt or clang-format.txt.