How to input letters (characters) into a char array in C++

3 Answers

0 votes
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	char arr[64];

	cout << "Enter string: ";
	cin.get(arr, 64);
	cout << "arr = " << arr << endl;

	return 0;
}

/*
run:

Enter string: c++ programming
arr = c++ programming

*/

 



answered Apr 4, 2018 by avibootz
0 votes
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	char arr[64];

	cout << "Enter string: ";
	cin >> arr;
	cout << "arr = " << arr << endl;

	return 0;
}

/*
run:

Enter string: c++programming books
arr = c++programming

*/

 



answered Apr 4, 2018 by avibootz
0 votes
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	char arr[64];

	cout << "Enter string: ";
	cin.getline(arr, 64);
	cout << "arr = " << arr << endl;

	return 0;
}

/*
run:

Enter string: c++ c c#
arr = c++ c c#

*/

 



answered Apr 5, 2018 by avibootz

Related questions

1 answer 144 views
2 answers 180 views
1 answer 198 views
1 answer 139 views
139 views asked May 20, 2018 by avibootz
1 answer 138 views
2 answers 158 views
1 answer 157 views
...