NOT ABLE TO ENTER STRING DATA

Write your question here. How come I am not able to enter a string into s or t?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main(void)
{
	// set variables
	string s;
	string t;
	// get lines of text
	cin >> "Enter string s: " >> s;
	cin >> "Enter string t: " >> t;

	printf("Character string s: %s/n", s);
	printf("Character string t: %s/n", t);
}
cin >> "Enter string s: " >> s;

cin >> is for input - I think you want to output the "Enter string s: " message to the user?

The escape character for new line is \n not /n.

1
2
3
4
5
6
7
	cout << "Enter string s: "; 
	cin >> s;
	cout << "Enter string t: ";
	cin >> t;

	cout << "\nCharacter string s:\n" << s;
	cout << "\nCharacter string t:\n" << t;


Enter string s: Enter string t: 
Character string s:
Hello
Character string t:
World
Last edited on
Thank you. I should know better.
Topic archived. No new replies allowed.