Arrays

closed account (NUj6URfi)
I want to use multiple string arrays. I just started my program and I have an error of

7 `std::string time[500][1]' redeclared as different kind of symbol

My code is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int i;
string plane[500][1];
string time[500][1];
int terminal[500][1];
int runway[500][1];
int main() {
    i=0;
    plane[i]="Flight815";
    cout << plane[i];
    cout << "Welcome to the air traffic control program or A.T.C.P.. What would you like your A.T.C.P. do?";
    i++;
    plane[i]="Flight816";
    cout << plane0 << plane1;
}
 



I am making this program to learn more about the language. I am trying to get strings of these categories (being the array names) to make an history of the plane flights (made up of course) for a log and also make sure the plane's flights don't interfere with each other. I put in the last few lines of code to test this program. My other errors are

85 C:\ProgramFiles\Dev-Cpp\include\time.h previous declaration of `time_t time(time_t*)'

7 declaration of `std::string time[500][1]'

85 C:\ProgramFiles\Dev-Cpp\include\time.h conflicts with previous declaration `time_t time(time_t*)'

In function `int main()':

12 incompatible types in assignment of `const char[10]' to `std::string[1]'

16 incompatible types in assignment of `const char[10]' to `std::string[1]'

17 `plane0' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

17 `plane1' undeclared (first use this function)
Last edited on
closed account (NUj6URfi)
Please help.
closed account (Dy7SLyTq)
http://www.cplusplus.com/doc/tutorial/arrays/
Get rid of using namespace std; or rename your time array.
closed account (NUj6URfi)
Now I have the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
using namespace std;
int i;
string plane[500][1];
int hop[500][1];
int mop[400][1];
int terminal[500][1];
int runway[500][1];
int main() {
    i=0;
    plane[i]="Flight815";
    cout << "Welcome to the air traffic control program or A.T.C.P.. What would you like your A.T.C.P. do?";
    i++;
    plane[i]="Flight816";
    cout << plane0 << plane1;
}


and the errors


12 incompatible types in assignment of `const char[10]' to `std::string[1]'
15 incompatible types in assignment of `const char[10]' to `std::string[1]'
16 `plane0' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
16 `plane1' undeclared (first use this function)
closed account (NUj6URfi)
I want this program to print flight815 and flight816 so I know the program works. I know I have to put cin.get(); and return0; at the end.
closed account (Dy7SLyTq)
seriously did you read my link? its not going to work. your using 2-d arrays wrong
closed account (NUj6URfi)
How can I get this to work in the way I want?
string plane[500][1];

This creates a 2 dimentional array of strings. Which basically means you have an array of arrays.

So you have an array of 500 arrays of 1 string.

Rather than the more obvious: array of 500 strings... which would just be string plane[500]; which is probably what you intended.


Furthermore... if creating an array named plane does not also create variables named plane0, or plane1. You only have plane. If you want to access individual elements in that array, you need to put the index inside of [brackets].

ie: plane[0] = "whatever"; will change the first element (the element at index 0) to "whatever".
As an alternative to an array of an array of stringsā€¦ Could you just use a std::map (or std::multimap)?

Edit: I don't know what you have in mind. On a second read, maybe just get rid of all the 2 dimensional arrays. And use std::vector<std::string> instead of an array of 500 std::strings.
Last edited on
closed account (NUj6URfi)
If i get rid of the [1] will my program work as intended?
closed account (NUj6URfi)
Also i never learned std. Instead of std::cout<<""; you can just use cout<<"";.
closed account (G309216C)
Hi,

So how is this related to do with Windows API in fact it does not contain a single Windows API function let alone any complex Windows specific platform.
Why don't people think before they post a thread.

Thanks!
Why don't people think before they post a thread.

Maybe for the same reason people resurrect 2-day dead threads to contribute no-content posts?
Topic archived. No new replies allowed.