I have seen an array struct in C that can hold data even if they are a different type. I forgot what that code was and I don't have the code on me at the moment. So I was wondering if anyone could show me how I would do this in C++.
tomtetlaw -1 Posting Pro
Recommended Answers
Jump to PostIf you want it to be an array you can do what Clinton was doing minus the mistakes. Try this code, it compiles just fine under gcc
#include <iostream> using namespace std; int main() { int a = 1; double b = 2.0; char c = 'c'; …
Jump to PostHow about using strings to represents float, char, double, int, and so on.
string Types[4] = { "124","1.234","aString","c" };
Then you can convert it accordingly with sstream.
All 8 Replies
Clinton Portis 211 Practically a Posting Shark
tomtetlaw -1 Posting Pro
tomtetlaw -1 Posting Pro
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
necrolin 94 Posting Whiz in Training
necrolin 94 Posting Whiz in Training
Clinton Portis commented: Good clear example on a topic that had me stumped. +5
Clinton Portis 211 Practically a Posting Shark
mrnutty 761 Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.