C++ :: Storing Numbers Into 2D Array - Invalid Types Int For Array Subscript
May 17, 2014
#include <iostream>
#include<fstream>
int decryption(int);
int multiply(int,int[][2]);
using namespace std;
main(){
int n;
ifstream inFile;
inFile.open ("out.txt");
[Code] .....
I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:
I just started learning about pointer and reference. * and &
The assignment is " Write a program that stores the following numbers in the array named miles:15,22,16,18,27,23, and 20. Have your program copy the data stored in miles to another array named dist, and then display the values in the dist array. YOur program should use pointer notation when copying and displaying array elements.
And this is what i have so far. But there is an error. I highlighted it with red. It says it's incompatible...
#include <iostream> using namespace std; const int arraynumb = 7; // declaration of keys: number of characters of keys void copyfunc(int *[], int); // function initialized int main() { int miles[arraynumb] = {15, 22, 16, 18, 27, 23, 20};
I've been getting this expression of "subscript being out of range" for my program but i'm not sure how exactly. I'm fiddling around with code, i'm trying to make a two dimensional array of random numbers, here is my code, it compiles just fine:
I need a translate (in both directions) all primitive types, into char[] (will be stored in string)
I understand how to manipulate integral types with bits and I cant just cut them down and shift them, but float and double don't work with this manipulation. So, how I can create a perfect bit copy of float and double?
int i = 0xFCED03A4; //Random number char c[4]; c[0] = ((i >> 3) & 0xFF); c[1] = ((i >> 2) & 0xFF); c[2] = ((i >> 1) & 0xFF); c[1] = (i & 0xFF);
[Code]...
This is basic stuff but I need an equivalent for float and double types, and it needs to be a perfect BIT copy, not value copy.
I am trying to create a generic map container which shell contain data of different datatypes. I already found a solution in this forum here:
[URL]...
Introducing a container with a Base Class as content type and inserting objectes of Derived Class types from that Base Class suites my implementation very well. But it is not really working. I implemented it this way:
class MyType { public: MyType() {} virtual ~MyType() {} }; template <class PT> class ParseType : public MyType
[Code]...
Then I insert one element.
// index being an object of type Parser<string> ParseType<string>* test = new ParseType<string>( index ); // and index.val(0) = "-n" iMap.insert( pair< string, MyType* >( index.id(0), test ) );
Now I think I should be able to call
const string key("-n"); iMap.at(key)->content->val(n); Or iMap.at(key)->get_val(n);
But neither one compiles with the error that "class MyType" (as the map container is pointing to a MyClass object) has no member/member function "content"/"get_val".
I also tried introducing member and member function "content" and "get_val" in "class MyType", which I thought should be hidden while constructing ParseType<string>. This would compile but it does not call the member "content or member function "get_val" from class ParseType.
A second try was to remove templatization of "class ParseType" and introduce a specific, let's say, "class ParseString" for objects of type Parser<string>. But the problems remain the same either the compiler complains due to missing member/member function or retreiving the map content will not call the derived class member/member function.
Code: /data/data/com.n0n3m4.droidc/files/temp.c:92:3: error: invalid use of template-name 'Array' without an argument list Array::Array(int s): size(s) ^ compilation terminated due to -Wfatal-errors.
Code:
// headers #include <iostream> #include <utility> #include <cctype> // stuff we need from namespace std using std::cout; using std::cin;
i want to modify value of whole array by passing it to a function and make each value of array multiplied by 3 ,return the value to main and print it using pointer.
error : invalid Lvalue is the error
Code:
#include<stdio.h> main() { int i,arr[10]; for (i=0;i<=9;i++) { printf("Enter value of arr[%d] : ",i); scanf("%d",&arr[i]);
I have a base class Building. Then come its children classes - Commercial Building and Residential Building. The third level is composed of Apartment and House classes, both inherit from Residential Building.
I need to create an array of 20 elements that will store info about all these different types of buildings(Commercial Building,Residential Building,Apartment, House). How should I proceed?
I want to create filenames such as Query.student.1.bin and save them in an array. I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
for(int i = 0 ; i < SIZE ; i ++) { scanf("%d" , & selection[i]); srand((unsigned) time(&t)); draw[i] = rand() % 50; //feeling could be a problem with this line of code :::::
}
is it possible to do this. i am trying to get 6 different numbers stored into 6 elements of an array . this is the piece of the code i think there is a problem with. ie my program scans the numbers and then crashes at this point so think it could be something to do with the commented line?
For some reason the integer array, arr[100][50], declared in main is not storing the correct values when passed through the function charArrayToIntArray.
I made an output right in the function to show how the array is not keeping the proper values, although when I output the array from within the loop in the function, it shows the correct values.
here is my problem given below Input values (say 10) from user in array, if the value is even then place at even index else at odd index. Then how could i solve this problem?