Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed yesterday.
Improve this question
I am trying to output a hex value using a variable for the number. Here is an example of it with no var.
system("echo '\x6e'");
//output:
//n
Perfect.
But this doesn't work:
for (int i=1; i<7; i++) {
system(("echo '\x"+to_string(i)+"e'").c_str());
}
//Which does not even compile.
//compiler:
//error: \x used with no following hex digits
Well if you actually let the code run there would BE hex digits. I try \\x but then it just literally prints \x1e etc.
The comment explains the issue. Possible solution
system(("echo '"s + static_cast<char>(i * 16 + 0xe) + "'").c_str());
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I made a simple c++ program:
#include <iostream>
int main(){
for (int i = 0; i >=; i++){
std::cout << i << "\n";
}
return 0;
}
It compiles but the output .exe doesn't run.
Edit: I used GNAT Studio 2021 compiler.
The termination condition is incorrect : i >=.
You can choose a number of turn of the loop, for exemple 10 with : i<=10.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm trying to use ostringstream to concatenate a string in a loop. Unfortunately, only the most recent stream is used. Can anyone point me in the right direction on accomplishing this or similar (other the + with string concatenation)?
Thanks
std:ostringstream os;
for (int i = stk.pop(); i != 0; i = stk.pop()) {
os << i << endl;
}
cout os.str();
So the value of 'os' is overwritten every time? Is there a way to append to the stream?
SOLUTION
This code works, I had a bug.
Thanks
That code shouldn't be overwriting os. It should be appending to it using the << operator. Perhaps your bug is elsewhere? Maybe your stack only really has the last element?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
following is my code for the program that will print out the random position contained values of nodes of a linked list. The problem is that my list is not printing the complete result. It prints only one result and thus. Please tell me where i am wrong.
int main(){
List* n;
int value=3;
int *counter=0;
collect(value,counter);
for(int i=0; i<&counter; i++);
{
count<<"\n Shuffled: "<< n.pickanddestroy();
}
}
Remove the semicolon at the end of the first line of your for loop.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have just started to learn C++ and i would like to get some help.
The user needs to type an ID number and the format has to be the following. The first character B and the other 4 any integer.
Im trying to check if the character format are right.
So far i have this:
if ((isalpha(id[0])=='B' ) && (isdigit(id.at(1))) && (isdigit(id.at(2))) ......
{
//do something
}
else
{
cout << "Wrong format" << endl;
}
but even if i type example B8745 it says wrong format.
You are comparing the result of isalpha, which is boolean, to character literal 'B'.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have to get numbers from file and some of them are negative. So, how can I do that? (C++)
Now I'm trying just this (without something special):
U1.txt file:
4 5 -1 6 -2
My code:
ifstream fd(FD);
int n1,n2,n3,n4,n5;
fd>>n1>>n2>>n3>>n4>>n5;
Your code is basically correct, except for that typo with n4 missing.
This:
ifstream fd("U1.txt");
int n1,n2,n3,n4,n5;
fd>>n1>>n2>>n3>>n4>>n5;
Will do what you expect, modulo error conditions.