« first day (1491 days earlier)      last day (1352 days later) » 

user13168561
2:39 AM
Hello people!
 
user13168561
How're you doing?
 
user13168561
I got a question...
 
user13168561
My question is that I want to store input in the vector. But the thing is that it has ',' in the input... For example iput is 10,23,45 and then the inputs stored in a vector, and is outputted as
 
user13168561
10
23
45
 
user13168561
This is the code:
 
user13168561
2:44 AM
------------------------------
vector<int> parseInts(string str) {
stringstream ss(str); //??
vector<int> result;
char ch;
int tmp;
while(ss >> tmp) { //??
result.push_back(tmp);
ss >> ch; //??
}
return result;
----------------------------------
 
user13168561
Can you explain to me how it's doing???
 
tmp is int, so ss put 10 into tmp
then you have another char variable ch
ss >> ch would put , to ch
if you don't have ss >> ch, , will be ignored, and ss >> tmp will try to put next possible int to tmp. Of course these are all byte strings, >> operator does some tricks internally.
it's reading the stream, not writing into the stream
I think you get it ;)
 
user13168561
Yup! That's why i deleted it haha...
 
user13168561
Thanks for helping out Rick :)
 
you're welcome :P
 
 
12 hours later…
2:55 PM
What's it called for a good programming practice for data type hierarchy?
Like putting boolian, const int, then int, etc.
 
nwp
Avoidance?
Packing?
Layout?
Alignment?
 
Thanks. Looking into those...
 
nwp
If I keep guessing I'll probably hit the correct term eventually.
 
I just mean at the start where you're listing variables
const int numReadings = 100;
int readIndex = 0;
double readings[numReadings];
 
nwp
What start where you're listing variables? That doesn't sound like something you should be doing.
 
2:58 PM
I just want to have a good practice to be consistent with
 
nwp
About the order of variable definitions?
 
yes!
 
nwp
As late as possible for each variable. If there are multiple put related variables together. Otherwise pick whatever. That'd be my guide.
 
:) pick whatever
The issue is that I want each sub-program to be copy/pasted into future (larger) programs
So the ordering is gonna be messed up anyway
Thanks nwp
 
nwp
3:32 PM
Copy/pasting sub-programs, especially implementations of different functions into a single function, doesn't sound like a good way to go about writing complex programs.
 
user7659542
you typically learn this the hard way
 
3:58 PM
[a...b,c...d] what does this expression mean?
@nwp
???
 
24 messages moved from Lounge<C++>
@Pole_Star also please don't randomly ping people
 
ok
 
4:25 PM
Just Arduino programs
nothing complex, basic modular functionality
Like sensors (weight, range, etc.)
 

« first day (1491 days earlier)      last day (1352 days later) »