trying to use the getline() function after an initial use of cin

Pages: 12
I'm not sure what you're asking. If it's a technical point, please clarify, and I may be able to answer.

If it's just a good old debate where people share opinions, then - well I'm still not sure of the question, but I'm less inclined to get involved.
I never thought of it as a debate not until you mentioned it.

Anyways, I decided to ask for your opinion because it's not the first time I've heard people raise concerns about .NET framework and MFC, and since I'm currently using this framework to learn and develop, I just wanted to make sure I'm on the right path and if not, then it would be wise that I seek counsel as regards the best way to go about being a rounded C++ software developer.

So, that's my question - is it safe to learn with Visual C++?
You seem to be asking two different questions:

1) Is it advisable to use Visual C++ when learning C++?

2) Is it advisable to use .NET and MFC when learning C++?

Answers:

1) Sure. You can use Visual C++ to write vanilla, standard-compliant C++ code. The IDE has a ton of useful features - in particular a very slick and easy-to-use debugger - that will help make your life easier.

2) I would say best not, at first. I'd advise learning to program in plain, standard-compliant C++. That's a skill you can use on different platforms, and with different frameworks. Once you've mastered that, then .NET/MFC would be useful things to learn as extra tools, but you don't want to be reliant on them, as that will limit the platforms you can program on.
@MikeyBoy @Chervil. Thank you for the heads up. I'll keep that in mind. That is, concentrate on just standard complaint c++ for now. Thank you.
@Chrevil
@Mikeyboy

Here's the revised code as promised for your review, comments and correction. Thanks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include<iomanip>
#include<string>

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

using std::string;
using std::getline;

//Function prototypes
bool getData(double& rNum, string& Str);
//void setData(double& pNum, string& pStr);
void showData(const double pNum[], const string pStr[], const int size);

int main()
{
	//Data
	double number;
	string buffer;

	//Data Stores
	size_t arraySize{ 1 };

	double* pNumber{ new double[arraySize] };
	string* pString{ new string[arraySize] };

	double* nTemp{};													//Temporarily hold number
	string* sTemp{};													//Temporarily hold string

	size_t index{};												

	for (;;)
	{
		//Call input function
		if (!getData(number, buffer))
			break;
		//Store each data input
		pNumber[index] = number;
		pString[index] = buffer;
		index++;
		if (index == arraySize)
		{
			arraySize++;												//i.e. increase the array size
			nTemp = new double[arraySize];								//A fresh array is declared with a
			sTemp = new string[arraySize];															//corresponding increase in array dimension

			for (size_t i{}; i < index; ++i)
			{
				*(nTemp + i) = *(pNumber + i);							//Copies existing and new entries
				*(sTemp + i) = *(pString + i);
			}
			delete[] pNumber;											//frees up memory storage
			delete[] pString;

			//Reburse data
			pNumber = nTemp;
			pString = sTemp;

			nTemp = nullptr;
			sTemp = nullptr;

		}
	}
	cout << "\nData stored in arrays:\n";
	showData(pNumber, pString, index);
}
//Function to get, pass and store data
bool getData(double& rNum, string& rStr)
{
	cout << "Enter a number, or 0 to end: ";
	cin >> rNum;
	cin.ignore(1000, '\n');											//discard Newline from cin buffer

	if (rNum != 0)
	{
		cout << "Type a string (or press only Enter to exit): "
			<< endl;
		getline(cin, rStr);
	}
	return((rNum != 0) && (rStr != ""));
}
//Function to display data stored
void showData(const double aNum[], const string aStr[], const int size)
{
	for (int i{}; i < size; i++)
		cout << std::setw(8) << aNum[i] << "  " << aStr[i] << '\n';
}
Last edited on
Hello
Chervil
, I hope you got my mesage. Thank you
Topic archived. No new replies allowed.
Pages: 12