Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's another version of the code that is (hopefully) a bit more flexible. It finds the "(" sing, then ")", splits them with a comma, strips all the whitespace characters and converts the numbers into integers. Then it prints them out.</p> <pre><code>#include &lt;string&gt; #include &lt;iostream&gt; using namespace std; //these three functions are taken from here: //http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring #include &lt;algorithm&gt; #include &lt;functional&gt; #include &lt;cctype&gt; #include &lt;locale&gt; static inline std::string &amp;ltrim(std::string &amp;s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun&lt;int, int&gt;(std::isspace)))); return s; } // trim from end static inline std::string &amp;rtrim(std::string &amp;s) { s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun&lt;int, int&gt;(std::isspace))).base(), s.end()); return s; } // trim from both ends static inline std::string &amp;trim(std::string &amp;s) { return ltrim(rtrim(s)); } int main() { string s = "std::vector&lt;int&gt;(612,30)"; int paren_start = s.find("(")+1; string numbers = s.substr(paren_start, s.find(")")-paren_start); int comma_pos = numbers.find(","); string first_num = numbers.substr(0, comma_pos); string second_num = numbers.substr(comma_pos+1, numbers.size()-comma_pos); int first = atoi(trim(first_num).c_str()); int second = atoi(trim(second_num).c_str()); cout &lt;&lt; "{" &lt;&lt; endl; for(int i=0; i&lt;first; i++) { cout &lt;&lt; second &lt;&lt; " "; } cout &lt;&lt; "}" &lt;&lt; endl; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload