Is there anyway to get a NonNullTerminated string?
Is there anyway to get a NonNullTerminated string?
Strings are always non-null terminated. Unless you are referring to arrays of chars.
search for std::string
[code]
your code here....
[/code]
I'm refering to an array of chars because those strings aren't that good with files..
>> Is there anyway to get a NonNullTerminated string?
That is about as descriptive as saying: "Can I get an int that equals 12?".
Geez.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Well, I won't try to convince you of something different, but I don't use those relicts from the past at allOriginally posted by sPlOrYgOn
I'm refering to an array of chars because those strings aren't that good with files..
Anyway, I'm still not sure if I understand your problem, but you could try to truncate the last char, or create them without a \0 at the end.
The only problem is, that unless you hand it to a function that takes a lenght as parameter, the function will read all data in the string and then begin to read data behind the string (because of the missing \0). It will continue to do so until - by chance - it hits a \0 in memory.
edit: btw, this is a very bad thing to do
[code]
your code here....
[/code]
>I'm refering to an array of chars because those strings aren't that good with files..
For an array of char to be considered a string you must terminate it with nul, or have some other way of determining the length. How is the std::string class not good with files? Are you using FILE*'s or something?
My best code is written with the delete key.
im doing binary files
[edit]
and everytime i save the structure with the string in it the string will be all messed up thats y i use an array of chars
[/edit]
I've got this one licked!
Use an array of ints instead and fill each element with the ascii code instead of the letter.
To print it cast as char.
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.
OS: Windows XP
Compiler: MSVC
Give an example of how you are reading/writing to the file. Chances are you are making a *very* common mistake.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
You can't save a string like that. It's an object. You need to save the strings data.Originally posted by sPlOrYgOn
im doing binary files
[edit]
and everytime i save the structure with the string in it the string will be all messed up thats y i use an array of chars
[/edit]
string.data()
Give this link a chance
[code]
your code here....
[/code]
i'm saving the files like this
and the array of ints sounds good but i dunno the number for the lettersCode:fout.write((const char*)MyStructure, sizeof(Structure));
[edit]
i save strings just fine in binary files
[/edit]
my solution was kind of a joke I don't suggest you use it, but nonetheless, it is a 2minute job to display the ascii charset:
Code:#include <iostream> using namespace std; int main() { int x; for(x=0 ; x<255 ; x++) cout << "No. " << x << " \t" << static_cast<char>(x) << endl; return 0; }
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.
OS: Windows XP
Compiler: MSVC
i found a bigger chart
http://sPlOrYgOn.distanthost.com/Chart.php?min=0
only problem is that's not ascii.
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.
OS: Windows XP
Compiler: MSVC
>fout.write((const char*)MyStructure, sizeof(Structure));
Is MyStructure a pointer? If yes, then the above should work. Otherwise try:
fout.write((const char*)&MyStructure, sizeof(Structure));