How to output a vector double? And stop before my integer
How to output a vector double? And stop before my integer.
I have a list of number with variable lenght say:(!w/ lines)
325 25 25 25 50 255 255 255 255
0.3 0.7
2
And I already taken the number before 0.3 but now I want to keep 0.3 0.7 in a vector but keep 2 as an integer for further uses. I tried with to push value but I dont know how to stop. Because my length of any line can change according to plan. I push everything in a structure for ease of use(maybe?)
typedef vector<int> PIXEL;
struct Donnee{
int color;
PIXEL colour;
vector <double> values;
int filter;};
int main{ Donnee Donnee}
void input(Donnee & Donnee){
cin >> Donnee.color;
Donnee.colour = couleur(Donnee.color);//it makes a vector according to size of Donnee.color
cin >> //where I want my double value
cin >> // where I want my int
Is there a way without using string and getline or is it necassary here? Thank you and sorry for bad english.
c++ vector struct int double
add a comment |
How to output a vector double? And stop before my integer.
I have a list of number with variable lenght say:(!w/ lines)
325 25 25 25 50 255 255 255 255
0.3 0.7
2
And I already taken the number before 0.3 but now I want to keep 0.3 0.7 in a vector but keep 2 as an integer for further uses. I tried with to push value but I dont know how to stop. Because my length of any line can change according to plan. I push everything in a structure for ease of use(maybe?)
typedef vector<int> PIXEL;
struct Donnee{
int color;
PIXEL colour;
vector <double> values;
int filter;};
int main{ Donnee Donnee}
void input(Donnee & Donnee){
cin >> Donnee.color;
Donnee.colour = couleur(Donnee.color);//it makes a vector according to size of Donnee.color
cin >> //where I want my double value
cin >> // where I want my int
Is there a way without using string and getline or is it necassary here? Thank you and sorry for bad english.
c++ vector struct int double
1
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Usegetline
to read the lines, stuff them in to astringstream
and happily fill yourvector
s from there. Withoperator>>
its not possible to reliable distinguish between an integer and a floating point number.
– Swordfish
Nov 25 '18 at 16:57
add a comment |
How to output a vector double? And stop before my integer.
I have a list of number with variable lenght say:(!w/ lines)
325 25 25 25 50 255 255 255 255
0.3 0.7
2
And I already taken the number before 0.3 but now I want to keep 0.3 0.7 in a vector but keep 2 as an integer for further uses. I tried with to push value but I dont know how to stop. Because my length of any line can change according to plan. I push everything in a structure for ease of use(maybe?)
typedef vector<int> PIXEL;
struct Donnee{
int color;
PIXEL colour;
vector <double> values;
int filter;};
int main{ Donnee Donnee}
void input(Donnee & Donnee){
cin >> Donnee.color;
Donnee.colour = couleur(Donnee.color);//it makes a vector according to size of Donnee.color
cin >> //where I want my double value
cin >> // where I want my int
Is there a way without using string and getline or is it necassary here? Thank you and sorry for bad english.
c++ vector struct int double
How to output a vector double? And stop before my integer.
I have a list of number with variable lenght say:(!w/ lines)
325 25 25 25 50 255 255 255 255
0.3 0.7
2
And I already taken the number before 0.3 but now I want to keep 0.3 0.7 in a vector but keep 2 as an integer for further uses. I tried with to push value but I dont know how to stop. Because my length of any line can change according to plan. I push everything in a structure for ease of use(maybe?)
typedef vector<int> PIXEL;
struct Donnee{
int color;
PIXEL colour;
vector <double> values;
int filter;};
int main{ Donnee Donnee}
void input(Donnee & Donnee){
cin >> Donnee.color;
Donnee.colour = couleur(Donnee.color);//it makes a vector according to size of Donnee.color
cin >> //where I want my double value
cin >> // where I want my int
Is there a way without using string and getline or is it necassary here? Thank you and sorry for bad english.
c++ vector struct int double
c++ vector struct int double
edited Nov 25 '18 at 17:12
Kevernier
asked Nov 25 '18 at 16:34
KevernierKevernier
63
63
1
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Usegetline
to read the lines, stuff them in to astringstream
and happily fill yourvector
s from there. Withoperator>>
its not possible to reliable distinguish between an integer and a floating point number.
– Swordfish
Nov 25 '18 at 16:57
add a comment |
1
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Usegetline
to read the lines, stuff them in to astringstream
and happily fill yourvector
s from there. Withoperator>>
its not possible to reliable distinguish between an integer and a floating point number.
– Swordfish
Nov 25 '18 at 16:57
1
1
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Use
getline
to read the lines, stuff them in to a stringstream
and happily fill your vector
s from there. With operator>>
its not possible to reliable distinguish between an integer and a floating point number.– Swordfish
Nov 25 '18 at 16:57
Use
getline
to read the lines, stuff them in to a stringstream
and happily fill your vector
s from there. With operator>>
its not possible to reliable distinguish between an integer and a floating point number.– Swordfish
Nov 25 '18 at 16:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469582%2fhow-to-output-a-vector-double-and-stop-before-my-integer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469582%2fhow-to-output-a-vector-double-and-stop-before-my-integer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
How did you manage to read the first line of integers and stop before 0.3? Why can't you use the same technique to read the second line and stop before 2?
– Igor Tandetnik
Nov 25 '18 at 16:36
Because the length of the line 0.3 and 0.7 can change and I wont know its size that's why I need to test for double and stop before int, the reverse (int ,double) I know how to do it. but I cant here
– Kevernier
Nov 25 '18 at 16:50
Do you really format code the way its shown in your question?
– Swordfish
Nov 25 '18 at 16:53
Use
getline
to read the lines, stuff them in to astringstream
and happily fill yourvector
s from there. Withoperator>>
its not possible to reliable distinguish between an integer and a floating point number.– Swordfish
Nov 25 '18 at 16:57