Prometheus
Anyone know if there's a way to directly get the result of getline() to go to say cout instead of to a string? Trying to skip the whole saving the line into a string thing.
Prometheus
copy each value from in to out until you reach an endline character? Otherwise use something as copy_until
I was trying to figure out how to do that but no matter where I looked everyone seems to say that you need to put the read charactor into a variable before directing it to cout. Never used copy_until. I'll look into it.
Anonymous
Hello where can I study c/c++ and get certificate
Anonymous
I really need to study
olli
I was trying to figure out how to do that but no matter where I looked everyone seems to say that you need to put the read charactor into a variable before directing it to cout. Never used copy_until. I'll look into it.
template <class I, class O> void foo(I & i, O & o) { char in; i >> std::noskipws >> in; while (in != '\n') { o << in; i >> in; } } does this what you want?
Prometheus
Here's a sample of what I wanted to do. Keep in mind I know its wrong already but it's an easy visual of what I was going for: getline(myfile, cout);
Prometheus
Instead of getline(myfile, mystring)
olli
Here's a sample of what I wanted to do. Keep in mind I know its wrong already but it's an easy visual of what I was going for: getline(myfile, cout);
like this? template <class In, class Out, class Pred> Out copyWhile(In in, Out out, Pred p) { while (p(*in)) { *out++ = *in++; } return out; } int main() { std::ifstream f("file.txt", std::ifstream::in); f >> std::noskipws; copyWhile(std::istream_iterator<char>(f), std::ostream_iterator<char>(std::cout, ""), [](const char & v) { return v != '\n'; }); }
olli
Thanks for the example. I'll have to give it a try. Just trying to optimize my code.
Depending on the implementation of the underlying stream, it might still be better to use std::getline performance-wise
Prometheus
Depending on the implementation of the underlying stream, it might still be better to use std::getline performance-wise
That's what I was thinking but at this point I'm up for trying anything lol
olli
how often do you call std::getline in your code? for each line in the file?
Prometheus
Yes, it's a loop that reads each line until eof.
olli
if you don't look at the individual lines, why not "copying" the whole file at once?
Prometheus
That was one option, I was going to try as a last resort, but I think that's only really efficient on smaller files. I'm not always aware of the file size before hand.
Prometheus
I'm testing on files that are only a few kb but I think if I tried it with files that are, for example, a few hundred mb I dont think it would be as efficient.
olli
so you are basically looking for the fastest way to copy to a stream?
Prometheus
Essentially. Fastest but if I can find one that balances speed and strain on hardware it would be best. I know it's a give and take a lot of the time, though. So I'm willing to try almost anything.
olli
Might be an interesting read then https://stackoverflow.com/questions/10195343/copy-a-file-in-a-sane-safe-and-efficient-way
Prometheus
I'll check it out. Thanks again for all the help
Joe
@linuxer4fun @ollirz just to let you know, i managed to get it to run just by compiling it on the linux device with the gcc compiler. I think I didn`t exmplain properly what my problem was and it was way easier than expected. thanks for your help anyways!
DaviC
Hello everyone, my question is: i have a c++ code in which there is a class's declarantion function follow by one assignment to its variable Like this: Class::function(parameters) : variable(value){ ... } Does anyone know what does it mean the code in "variable(value)"? Thank you😁
BinaryByter
it is like putting variable = value inside of the function body
BinaryByter
EXCEPT that the compiler will know exactly how to optimize that
BinaryByter
that means, that it won't contstruct variable being unitialized but it will construct it with value in it
DaviC
Ok thank you very much, i had never seen it before😊
BinaryByter
sure :D
BinaryByter
btw: i'd advise you to always use that over the body-initialization
BinaryByter
that way the compiler knows how to optimize the initialization
olli
Any c++ language lawyer in here? Is there really no compiler that issues a diagnostic? According to temp.res this should be ill-formed or shouldn't it? template <typename ...Ts> struct X { X(Ts ...args) : i(1337, args...) {} int i; }; int main() { X<> x; }
BinaryByter
it shouldn't I think
BinaryByter
wait i'll find the article
BinaryByter
BinaryByter
source:
BinaryByter
http://www.cplusplus.com/articles/EhvU7k9E/
olli
This is not the standard
BinaryByter
This is not the standard
they cite sources though
BinaryByter
and its quite reliable
BinaryByter
*i'm just a noob don't mind me*
olli
they cite sources though
And of course zero is valid, but a parameter pack is only valid if am empty pack is not the only viable option.
BinaryByter
huh?
olli
In this case adding any parameter makes it ill-formed obviously.
BinaryByter
Oh I see
olli
Let me cite the std
BinaryByter
well if you don't add any arguments it shoudl be fine
olli
The program is ill-formed, no diagnostic required, if: [...] every valid specialization of a variadic template requires an empty template parameter pack
BinaryByter
I see
Box of
Have you forced it to compile in C++11?
olli
Have you forced it to compile in C++11?
-std=c++1z -pedantic -Wall -Wextra
olli
Okay well apparently "no diagnostics required" means the compiler does not need to issue diagnostics or reject it
Seroney
Thanks
Anonymous
New here (lost here) Wtf is dis planet ?
Anonymous
Where ? Im human 😒
DaviC
Another question, if i have a uint32 variable that contains memory address and i want to convert it into binary number to find the opcode of my instruction, what should i do?
DaviC
What did you mean?
BinaryByter
you have an array of memory, right?
BinaryByter
(you are still writing, that emulator, right?)
DaviC
Yes
DaviC
Yes the both sorry
BinaryByter
alright
BinaryByter
so now you have a pointer to an opcode
BinaryByter
just access the memory at exactly that uint
BinaryByter
I hope that you use a memory model in which you map one byte in a vector to one memory adress
BinaryByter
(if your emulator works on smaller adress sizes, obviously you can use smaller or even bigger ones etc )
DaviC
In the instruction fetch i initialize my instruction uint32 with the value of the function readword(programCounter). Then i want to access to the opcode to decode my instruction but i cant access like an array
BinaryByter
why can't you?
DaviC
Can I write instruction[26] (if my opcode begin on bit number 26) and assign it to a char?
DaviC
To compare its value in an if?
BinaryByter
do you keep your instructions separate from RAM?
DaviC
No i load the program in the ram
DaviC
So i think they are inside my ram no?
BinaryByter
what?
BinaryByter
you should know, since you wrote the emulator
DaviC
No because my professor give me the skeleton, and i have to understand how it works