Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a simple way to use the <code>getline()</code> function :</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; int main(void) { string name; int age; cout &lt;&lt; "How old are you ?" &lt;&lt; endl; cin &gt;&gt; age; cin.ignore(); // for avoiding trouble with 'name' when we're gonne use getline() cout &lt;&lt; "What's your name ?" &lt;&lt; endl; getline(cin, name); system("PAUSE"); } </code></pre> <p>Don't forget it, if you use <code>cin</code> befor <code>getline()</code>, you have to put the line :</p> <pre><code>cin.ignore(); </code></pre> <p>So your code should looks like something like that :</p> <pre><code>int main() { vector&lt;person&gt; people; bool flag = true; int num_people = 0; //char*filename="names.txt"; people = read_file(); while(flag) { int sel = 0; string args; cout &lt;&lt; "1 - Sök del av personnamn" &lt;&lt; "\n" &lt;&lt; "2 - Sök städer" &lt;&lt; "\n" &lt;&lt; "3 - Avsluta" &lt;&lt; endl; cin &gt;&gt; sel; cin.ignore() if(sel == 1) { cout &lt;&lt; "Mata in delen av personnamnet" &lt;&lt; endl; getline(cin, args); print_result(find_in_names(people, args)); } else if(sel == 2) { cout &lt;&lt; "Mata in staden" &lt;&lt; endl; getline(cin, args); args = lower_letters(args); print_result(find_person_from_city(people, args)); } else if(sel==3) { flag=false; } else { cout &lt;&lt; "FEL, TRYCK OM!" &lt;&lt; endl; } } } </code></pre> <p>Here's some doc <a href="http://www.cplusplus.com/reference/istream/istream/ignore/" rel="nofollow">http://www.cplusplus.com/reference/istream/istream/ignore/</a>, hope it'll help;</p>
    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