title: c++ sscanf reading string vector
body: <p>thanks for the support on the <a href="https://stackoverflow.com/questions/12934436/c-read-from-stdin-store-in-vector-and-stdout">previous post</a>... i am now trying to store the vector string on another string and do a sscanf to check for a text eg. "TEXT" and if found append another text at the end of line....</p>
  
  <p>any ideas???</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  int main() {
    vector&lt;string&gt; vs;
    vector&lt;string&gt;::iterator vsi;
    string agent;
    string buffer;
    string line;
    while (!(cin.eof())) {
      getline(cin, buffer);
      cout &lt;&lt; buffer &lt;&lt; endl;
      vs.push_back(buffer);
    };
  
    vsi = vs.begin();
    for (int count=1; vsi != vs.end(); vsi++,count++){
      cout &lt;&lt; "string" &lt;&lt; count &lt;&lt;"="&lt;&lt; *vsi &lt;&lt; endl;
      line = *vsi;
      sscanf(line, "%s %[^\n]",text);
  //dummy code
  if text=="TEXT" do this:
      cout &lt;&lt; "agent" &lt;&lt; text &lt;&lt; "endl";
    }
  else: do nothing
  
  
    return 0;
  }
  
  
  
  [root@server dev]# g++ -o newcode newcode.cpp 
  newcode.cpp: In function ‘int main()’:
  newcode.cpp:24: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int sscanf(const char*, const char*, ...)’
  [root@server dev]# 
  </code></pre>
  
  <p>UPDATE:
  i used line.c_str() on sscanf and gives out this error</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  int main() {
    vector&lt;string&gt; vs;
    vector&lt;string&gt;::iterator vsi;
    string agent;
    string buffer;
    string line;
    while (!(cin.eof())) {
      getline(cin, buffer);
      cout &lt;&lt; buffer &lt;&lt; endl;
      vs.push_back(buffer);
    };
  
    vsi = vs.begin();
    for (int count=1; vsi != vs.end(); vsi++,count++){
      cout &lt;&lt; "string" &lt;&lt; count &lt;&lt;"="&lt;&lt; *vsi &lt;&lt; endl;
      line = *vsi;
      cout &lt;&lt; "LINE:" &lt;&lt; line.c_str() &lt;&lt; endl;
      sscanf(line.c_str(), "%s %[^\n]",agent);
   /*   cout &lt;&lt; "agent" &lt;&lt; agent &lt;&lt; "endl"; */
    }
  
    return 0;
  }
  
  [root@server dev]# g++ -o newcode newcode.cpp 
  newcode.cpp: In function ‘int main()’:
  newcode.cpp:25: warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime
  [root@server dev]# 
  </code></pre>
  
  <p>what i want to do is when a string on a particular line is detected it will append a text to the end of line and stdout...</p>