would this work?
The reinterpret_cast operator takes the form
would this work?
The reinterpret_cast operator takes the form
so what you are saying is only store it as char?
also i want it to stop at found which represents position of the '-'. So why doesn't static_cast or atoi work?
k. I will give that a try. So you can't input a string is that what you are saying?
already tried that it didn't work.
tried it gives same error.
yeah that is what i am trying to do in my if condition but i cannot convert my string to a int even though it contain nothing but integers.
but i don't know what number they could input, so i can't use find command.
the error message i get is :
cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char>>' to 'const char*...
What does that mean
i got first part to work. stuck on second part.
so here is what i am supposed to do:
Some students (as early as junior high or even as late as college) find reading assignment lists difficult. They see the teacher write something like 4-10 and do problem 4 and problem 10 — but not the other 5 assigned problems!
To help these poor lost souls, we'll write a program that can take in the (possibly) hyphenated assignment list and print back out a list of all problems assigned. Just in case, we'll also make sure our list is sorted (non-decreasing order) and contains no duplicates.
Here are some examples:
User Types In... We Display...
L1 Do problem 1 of L.
L1-3 Do problems 1, 2, and 3 of L.
L1,2,5 Do problems 1, 2, and 5 of L.
L1-3,5 Do problems 1, 2, 3, and 5 of L.
L1-3,5-7 Do problems 1, 2, 3, 5, 6, and 7 of L.
L1-1,3-3,5-8 Do problems 1, 3, 5, 6, 7, and 8 of L.
L4-5,1-3,7-10 Do problems 1, 2, 3, 4, 5, 7, 8, 9, and 10 of L.
L4-5,1-3,7-10,8-12 Do problems 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, and 12 of L.
Let the problem set name be either a single character, a single word (containing no digits), a quoted string, or even a quoted, space-containing string. The problem set name will always be entered first. If the user uses a quoted problem set …
it says problem is on line 25 and 26 where i am trying to cast the string substring into an integer since it contains integer values. static_cast wouldn't work
how can i cast a string to int when i have this
//input problem numbers
cout<<"\n""enter the numbers";
//numbers represents what they input
string numbers;
getline(cin,numbers);
//position represents at what location value comma is
int position;
while(numbers.find(',') !=string::npos)
{
//print out what the user inputs
//used to split up part between each comma
string substring;
//find position of each comma
position=numbers.find(',');
//represents first character in string numbers
int intial=0;
//find each part which contains a "-" and a number before the comma and store it in variable substring
substring=numbers.substr(intial,position);
numbers=numbers.erase(intial,position+1);
//if it has a - and a ' then do this
if(int found=substring.find('-') !=string::npos)
{
int beginValue = atol(substring.substr(0, found));
int endValue = atol(substring.substr(found+1));
int size=endValue-beginValue;
int substring_list[size];
for(int a=0; a<=size; a++)
{
for(int i=beginValue; i<=endValue; i++)
{
substring_list[a]=i;
}
}
cout<<"\n";
}
}
return 0;
}