I'm trying to learn C ++. I am now on the wire. I've written this simple method, to do string input Should ask for it and then return it. To do this, I am using the cin.getLine () method, but string print is not printed after using cin.getLine ()
string getString (four string []) {Cout & lt; & Lt; "Please enter a string to process"; Cin & gt; & Gt; String; Cout & lt; & Lt; "String in the gatestring before the process:" & lt; & Lt; String & lt; & Lt; "\ N"; Cin.getline (string, STRINGSIZE); Cout & lt; & Lt; "After String Processing:" & lt; & Lt; String & lt; & Lt; "\ N"; // String Return String is not printed here; } Does anyone help me understand what I'm doing is wrong? Thank you
You are first reading the string with std :: string < Code> CIN> & Gt; Read something from cin.getline (string, STREAMSIZE) to and then cin ; This is not necessary, read it once and return it: P> gets the string (four strings []) {cout & lt; & Lt; "Please enter a string to process"; Cin & gt; & Gt; String; Cout & lt; & Lt; "String in the gatestring before the process:" & lt; & Lt; String & lt; & Lt; "\ N"; // Take action on this, whatever you describe it is COT and LT; & Lt; "After String Processing:" & lt; & Lt; String & lt; & Lt; "\ N"; // string return string is printed; } Otherwise, if you want to use getline , then: std :: string name; Std :: cout & lt; & Lt; "Please enter your full name:"; Std :: getline (std :: cin, name); // or std :: getline (std :: cin, string, 'r'); To read / only the Seamankita character 'r' std :: cout & lt; & Lt; "Hello," & lt; & Lt; Name & lt; & Lt; "! \ N"; Such a thing to remember is not to use the getline or cin , unless there really is any special No reason
No comments:
Post a Comment