UTF-8 while compiling C++ for Geant 4 - c++

I am trying to run a program called Geant4, and I have this make file containing numerous .cc files involved in the program, but when I run it I get this error:
/Volumes/Silviu/Geant4/geant4.10.02.p02/examples/basic/B1/src/._B1PrimaryGeneratorAction.cc:1:4096: error:
source file is not valid UTF-8
I am not sure how to provide more details, but the point is that I have a file called B1PrimaryGeneratorAction.cc, but I am not sure what the error means, or what ._B1PrimaryGeneratorAction.cc actually represent. And what is a not valit UTF-8? Can anyone help please?

Inspect the "._B1PrimaryGeneratorAction.cc" file reported there. The name seems suspicious, maybe you extracted an archive incorrectly thus having a broken source file.
Also the position info ":1:4096" is kind of suspicious - it says that the invalid character is the 4096th character on the first line. Sounds like a corrupted file to me, just check that file contents (C++ source files usually do not have 4096 characters on a single line, although there can be exceptions indeed).
As far as I can tell, this might be the correct contents of the file:
http://geant4.web.cern.ch/geant4/UserDocumentation/Doxygen/examples_doc/html/B1PrimaryGeneratorAction_8cc_source.html
(and that file does not seem to contain any "strange" non-ASCII characters)

Related

Microsoft Speech to Text with non-ASCII file names

I'm playing with the Microsoft Speech API and the sample code at https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/samples/cpp/windows/console. The SpeechContinuousRecognitionWithFile() function in speech_recognition_samples.cpp is almost completely what I need.
Modifying this function, I replaced the name of the input file by that of another file which happened to be on my disk, "Blutgefäße.wav". This resulted in a std::range_error exception in the FromWavFileInput call, which could only be fixed by renaming the file to "Blutgefaesse.wav".
Is it expected behavior of this function to crash with international file names? Do I have to use a Unicode version of the API? If so, where do I find it?
The solution is to supply non-ASCII file names in UTF-8 coding:
u8"Blutgefäße.wav"
The transcript, by the way, is also UTF-8 encoded.

How to read .inp file in c++?

I have a dataset, a ".inp" format file, and I need to read this file in c++. However, the fopen() fread() method seemed to fail and read the wrong data(e.g. the first integer should be 262144, the fread yields an integer much larger than this nevertheless).
To be more specific, my ".inp" file contains a few integers and float points, how can I read them successfully in c++?
enter image description here
This is the screenshot of the "*.inp" file from Notepad++. Basically this is a text file.
I solved it by coping the data into a txt. However, I am still not aware how to read "*.inp"
I found some info about INP file extension. It seems like there are multiple variances of it, each meant to be used for different purpose. Where is your file coming from? As for soultion, if you can't open the file using fopen/fstream normally, you could treat it as binary and read each value in the way you specify. Other than that, I could think of calling system functions to get file contents (like cat in linux for example), then if there are some random characters, you could parse your string to ommit them.
Here is example of how to call cat in C++:
Simple way to call 'cat' from c++?

Checking an external file against set of functions and printing error alongwith line number using c++

I have a GEDCOM file, which I am supplying to my program, my program checks the content of GEDCOM file against a set of functions.
If the contents of file, fail to match the requirements of function, it should throw an error along with the line number on the GEDCOM file where error exists.
I would also like to mention that I have tried using macros like LINE, FILE but they are printing the contents of source code like line of source code and file name of source code.
Thanks in advance
If you are reading the file one line at a time you can keep a counter of the number of lines you have read from the file.
If you already have the whole file in one big buffer you can scan the number of newline or return characters.
If you provide a MCV example demonstrating your code reading in the file I can maybe help more.

unqualifed id error iOS

I am trying to compile an Xcode project and I am receiving a bunch of unwanted errors such as this
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/i PhoneSimulator6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:13:1: error: expected unqualified-id
The project works fine, but when I try to include this file "iRate.h" in my app delegate everything goes wrong. The app delegate class I am trying to include iRate is written in c++(cpp file). I don't know what other information you might need, but that pretty much sums it all up
Here is another error message, hopefully this will help out a bit
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:418:50: error: unknown type name 'NSString'
FOUNDATION_EXPORT Protocol *NSProtocolFromString(NSString *namestr) NS_AVAILABLE(10_5, 2_0);
^
^
If you are mixing C++ with Objective-C, you need to give your file the .mm file extension.
if you are using the c++ files in objective c, you need to have your objective-c files extension as .mm (obj-c++) instead of just .m (obj-c), have you tried that?
Check the very beginning and end of all your header and code files. Start with the first lines of all headers. I mean line number 1, where usually the comments are that you never look at. You might find one of them with a stray character or so just before the comment starts with //.
d// Copyright ...
(In my case it was a d because I have the habit of having the left middle finger on the d when I do nothing but thinking or so.)
Unfortunately you cannot tell which of the header files causes it. And it may well be a stray character at some implmentation or some interface end.
#end
d
Good luck!

Incorporating text files in applications?

Is there anyway I can incorporate a pretty large text file (about 700KBs) into the program itself, so I don't have to ship the text files together in the application directory ? This is the first time I'm trying to do something like this, and I have no idea where to start from.
Help is greatly appreciated (:
Depending on the platform that you are on, you will more than likely be able to embed the file in a resource container of some kind.
If you are programming on the Windows platform, then you might want to look into resource files. You can find a basic intro here:
http://msdn.microsoft.com/en-us/library/y3sk7e6b.aspx
With more detailed information here:
http://msdn.microsoft.com/en-us/library/zabda143.aspx
Have a look at the xxd command and its -include option. You will get a buffer and a length variable in a C formatted file.
If you can figure out how to use a resource file, that would be the preferred method.
It wouldn't be hard to turn a text file into a file that can be compiled directly by your compiler. This might only work for small files - your compiler might have a limit on the size of a single string. If so, a tiny syntax change would make it an array of smaller strings that would work just fine.
You need to convert your file by adding a line at the top, enclosing each line within quotes, putting a newline character at the end of each line, escaping any quotes or backslashes in the text, and adding a semicolon at the end. You can write a program to do this, or it can easily be done in most editors.
This is my example document:
"Four score and seven years ago,"
can be found in the file c:\quotes\GettysburgAddress.txt
Convert it to:
static const char Text[] =
"This is my example document:\n"
"\"Four score and seven years ago,\"\n"
"can be found in the file c:\\quotes\\GettysburgAddress.txt\n"
;
This produces a variable Text which contains a single string with the entire contents of your file. It works because consecutive strings with nothing but whitespace between get concatenated into a single string.