473,503 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading commands into an array from a text file

5 New Member
Hello,
I need to read in commands from a text file into an array and i just can't do it. I am trying to use the line filein>>patternarray[command];
and it doesn't work! can anyone help me?

Cheers
Aug 26 '06 #1
7 4762
Banfa
9,065 Recognized Expert Moderator Expert
You need to give a bigger example of your code and to describe how it doesn't work.
Aug 26 '06 #2
pb1uk
5 New Member
Hello,
the below is a segment of code from my program and is part of a switch statement case1:

cout <<"Enter the name of the pattern file you wish to load: " << endl;
cin >> patternfile;
filein.open(patternfile.c_str());
if(filein.good())
{
filein>>firstword;
while (firstword =="PATTERN")
{
filein>>patternarray[command];
}
}
i need the program to read in commands from a text file into an array so the array can be accessed to draw a pattern from.
Thanks for your time
Peter
Aug 26 '06 #3
pb1uk
5 New Member
Hello,
the below is a segment of code from my program and is part of a switch statement case1:

cout <<"Enter the name of the pattern file you wish to load: " << endl;
cin >> patternfile;
filein.open(patternfile.c_str());
if(filein.good())
{
filein>>firstword;
while (firstword =="PATTERN")
{
filein>>patternarray[command];
}
}
i need the program to read in commands from a text file into an array so the array can be accessed to draw a pattern from.
when executing i get the following error:
C:\Documents and Settings\Peter Briers\My Documents\NEW COURSE\SW design and Imp\Labs\wk12\soft10071\cwork1\main5.cpp(60) : error C2677: binary '[' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.
which is to do with line 60 which is:
filein>>patternarray[command];

Thanks for your time
Peter
Aug 26 '06 #4
Banfa
9,065 Recognized Expert Moderator Expert
So not at execution time but at compile time then.

I am guessing that command is not an integer type, the error is basically telling you that whatever type command is (and I think it is a string from the error) it can not be used as an array index to patternarray because patternarray type doesn't define the [] operator with string as a type.

What type is patternarry? (vector of strings ???)
Aug 26 '06 #5
pb1uk
5 New Member
command is type string as is the array:

string command;
string patternarray[100];
Aug 26 '06 #6
Banfa
9,065 Recognized Expert Moderator Expert
OK well in that case

filein>>patternarray[command];

is never going to work

Since patternarray is an array (hmmm the clue seems to have been in the name :D) the expression in the [ ] must evaluate to an integer. Command is clearly a string not an integer, if it is a string containing an integer then you need to convert it to an integer first before using it. String may have a method or look up atoi and strtoul.
Aug 27 '06 #7
D_C
293 Contributor
Perhaps you should research enum.
Aug 28 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

40
4462
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
10
1670
by: T Cordon | last post by:
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: ñ, ó, ú, etc. Please Help. Thanks
1
1762
by: pb1uk | last post by:
hello, i need to read in commands from a text file. Once the first line is read into an array if it is a certain word then a certain amount of numbers are read into another array. i have been using...
3
1788
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
2
1729
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
2
2103
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
21
3015
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
3
2325
by: darklunar | last post by:
Hello I've been given this assignment where I am to read from a text file of a number of students with a list of their names and GPA. Here is the text: James 3.9 Margaret ...
1
4700
by: stoogots2 | last post by:
I have written a Windows App in C# that needs to read a text file over the network, starting from the end of the file and reading backwards toward the beginning (looking for the last occurrence of a...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.