New course! Every coder should learn Generative AI!
Try a free lesson0
What compiler should I use to allow the user to input the value of a string?
I've previously tried to write a program that would allow the user to input the value of a string. I was told that I needed to use a certain compiler in order to do that. Does anyone know what compiler I should use?
2 Answers
0
No, It's not about compiler. Maybe you mean library?
#include <iostream>
#include <string> //This one.
using namespace std;
int main(){
string myString;
getline(cin, myString);
cout myString;
return 0;
}
getline() means that you read the whole line, not only one word like cin >> myString; would do.
For example:
cin >> myString;
Input: Today is Friday.
Output: Today
getline(cin, myString);
Input: Today is Friday.
output: Today is Friday.
IDE(Where you can write and compile your code) like CodeBlocks does not require <string> library when you don't use any string functions like strcpy() and so on. In other IDE's like Visual Studio you need <string> library whenever you use string data type.
0
Thanks so much!
You're right, I did mean library.