473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write structure

1 New Member
Expand|Select|Wrap|Line Numbers
  1. struct info
  2.         {
  3.             string name, ID;
  4.             double GPA;
  5.         };
  6.  
  7.         static void Main(string[] args)
  8.         {
  9.             info[] student=new info [5];
  10.             Console.WriteLine("Enter the data : ");
  11.             for (int i = 0; i < 5; i++)
  12.             {
  13.                 student[i] = Console.ReadLine();
  14.             }
when i write this code it give me error
("Cannot implicitly convert type 'string' to 'ass.Program.in fo[]' ")

can i know what's the error about this code
Aug 12 '12 #1
2 2019
Rabbit
12,516 Recognized Expert Moderator MVP
You're trying to assign a string (the string you read from the console) into your struct (info). They are not the same type. A string is not the same thing as a struct.
Aug 12 '12 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Rabbit is referring to line 13 in the above code.
You have:
Expand|Select|Wrap|Line Numbers
  1.  student[i] = Console.ReadLine();
But it should be something like:
Expand|Select|Wrap|Line Numbers
  1. student[i].Name = Console.ReadLine();
If you are reading in a name at that point.

If you're reading in the GPA then it should be:
Expand|Select|Wrap|Line Numbers
  1. student[i].GPA = Console.ReadLine();
If you are expecting a string with all of the information about the student, then you should either create a function that accepts a string and puts the relevant information into the appropriate members of the struct...or you should consider implementing a constructor that takes a string and does this same process.

-Frinny
Aug 13 '12 #3

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

Similar topics

4
612
by: Stephan Tobies | last post by:
Hi everyone, I am looking for a good data structure that could be used to represent families of trees with shared sub-trees and copy-on-write semantics. On a very abstract level, I would like to have an API like this: Let Node be a suitably defined data structure. Then the following functions shall be supported:
7
3423
by: Randy Yates | last post by:
Hi, I work in an embedded environment in which we often use a mix of C and assembly code. Thus a recurring requirement is to be able to take a C header file with structure definitions as input and create an assembly include file with the structure member offsets defined. The problem is that the structure offsets are a complicated function of other syntactic elements such as other structures (I could have a structure as a member of...
3
14511
by: Dae-Suk Chung | last post by:
Hi, What is the easiest way to write a struct(with biary data) to a file ? do I need to covert it through e.g. Marshal class ? Thanks for any tips! DaeSuk.
5
4327
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing text to a file there is no problem - that starts when I attempt to write the structure. Can someone help me out, please?
8
23900
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
2
1144
by: Hexman | last post by:
Hi All, I have created a structure for a record (as I did in the old days with assembler, cobol, etc.). It contains several fields with various types. Using it in arrays it functions nicely. Much the same as a datarow. I'm acquiring transactions from different sources, parsing them, validating them and placing the data into the structure. Now, I want to write these transactions to a file. How do I write the entire structure (one...
2
11447
by: shivapadma | last post by:
1.i am just trying to insert a "structure record" into a file using fwrite() function by the following code 2. #include<stdio.h> #include<conio.h> struct student { char name; int rollno; };
5
3805
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file. Here is my part of my code. struct cust_data { int nCAFID; char *szFirstName;
5
3788
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
11
3938
by: michelqa | last post by:
Hello, I can retrieve column text from a ListView in another process but I cant figure out how to access to structure elements (LVCOLUMN) <code> //Handle variable is a valid ListView handle LV_COLUMN ListViewItem = new LV_COLUMN(); IntPtr ListViewItemPointer = IntPtr.Zero;
0
8413
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
4173
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2742
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.