+ 2
String input
Can i take input from user string values with space, if i can than how
11 Antworten
+ 5
You can use getline()
string inp;
getline(cin, inp);
+ 3
#include <iostream>
#include <string>
int main() {
std::string input;
std::cout << "Enter string: ";
std::getline(std::cin, input);
std::cout << "You entered : " << user_input << std::endl;
return 0;
}
+ 2
difference between cin and getline(cin, input)... cin take the value when a space is reached. getline(cin) gets the entire line as a string.
#include <iostream>
using namespace std;
int main() {
string address;
getline(cin, address);
cout << address << '\n';
int n1, n2, n3;
cin >> n1 >> n2 >> n3;
cout << n1 << endl;
cout << n2 << endl;
cout << n3 << endl;
}
/*
Example input
221B Baker Street
7 11 42
submit
*/
+ 2
using C++ to program an AI is not a beginner project....
+ 1
Is that will allow to use spase
+ 1
Wow it’s work thanks aging Lisa...
+ 1
Ya ya i get it man, thanks for your kindness....
+ 1
actually I am trying to make simple AI. if I learn something then I put it in that....
+ 1
yeah but I like difficulty...
if I learn something new then I added I am just writing something in future maybe it work
+ 1
if you want your user to be able to add spaces in their input with characters, try using the getline() function, here is an example of how to use it.
#include <iostream>
#include <string>
int main() {
std::string input;
std::getline(std::cin, input);
std::cout << input;
return 0;
}
the line of code that says std::getline(std::cin, input) gets the users console input, then it will print it out at the end! I hope that this helped you!
0
do you have any suggestion for me...