473,568 Members | 2,923 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>>pattern array[command];
and it doesn't work! can anyone help me?

Cheers
Aug 26 '06 #1
7 4769
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(pat ternfile.c_str( ));
if(filein.good( ))
{
filein>>firstwo rd;
while (firstword =="PATTERN")
{
filein>>pattern array[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(pat ternfile.c_str( ));
if(filein.good( ))
{
filein>>firstwo rd;
while (firstword =="PATTERN")
{
filein>>pattern array[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\s oft10071\cwork1 \main5.cpp(60) : error C2677: binary '[' : no global operator defined which takes type 'class std::basic_stri ng<char,struct std::char_trait s<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>>pattern array[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>>pattern array[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
4479
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 line at a time and print it out. How can I do this? I wrote the code below but it's not correct since the fscanf reads one word (terminating in...
10
1685
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
1768
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 filein>>array; if(command =="MOVETO") { filein>>value1; filein>>value2; } etc it doesnt seem to want to work and the compiler does like my...
3
1799
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 read a lilne then put into the corresponding box...it just seems like a task i should be able to complete in a few lines...rather than quite a few...
2
1734
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 to write a program in C++ that would allow the user to enter student information (matriculation number, name, status and mark), which was then stored...
2
2108
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 questions. The program starts by outputting a simple text information screen: Question Master
21
3019
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 00000000_00 0 000 000 000 0000 000 I need to read the file line by line and eventually parse out each piece of the file and store in arrays that...
3
2328
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 3.5 Charles 1.2 Jennifer 4.0
1
4712
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 couple of strings in one line of text). I do not want to read the entire file, as it is very large, on a highly utilized server, and is updated with...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.