I would like to obtain information from a text file and assign that information into class objectsWhy should the “PIMPL” idiom be used?Why does an overridden function in the derived class hide other overloads of the base class?Returning ints versus void“Undefined reference to” template class constructorWhy is 'int i = i;' legal?Turbo C++ and Code blocksFunction ambiguous in multiple inheritanceHow do I read from an input file after passing the ifstream object to a function?Passing Array of objects to same class C++a function-definition is not allowed here: void encryption(ifstream encrypt_file, ofstream keys_out, ofstream cipher_out) {

Are there situations when self-assignment is useful?

What are these arcade games in Ghostbusters 1984?

How to convert to standalone document a matrix table

General purpose replacement for enum with FlagsAttribute

How does an ARM MCU run faster than the external crystal?

Why does the 6502 have the BIT instruction?

What are the benefits of cryosleep?

How to capture more stars?

Crossing US border with music files I'm legally allowed to possess

Seed ship, unsexed person, cover has golden person attached to ship by umbilical cord

Were pens caps holes designed to prevent death by suffocation if swallowed?

I think I may have violated academic integrity last year - what should I do?

How many chess players are over 2500 Elo?

Why do airplanes use an axial flow jet engine instead of a more compact centrifugal jet engine?

How to make a crossed out leftrightarrow?

analysis of BJT PNP type - why they can use voltage divider?

Full backup on database creation

Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?

How can I get exact maximal value of this expression?

Is this resistor leaking? If so, is it a concern?

How can I translate "would" in "He had to run faster than his tribemate, as the hindmost would be eaten by the lion"?

How bitcoin nodes update UTXO set when their latests blocks are replaced?

At what point in European history could a government build a printing press given a basic description?

Full horizontal justification in table



I would like to obtain information from a text file and assign that information into class objects


Why should the “PIMPL” idiom be used?Why does an overridden function in the derived class hide other overloads of the base class?Returning ints versus void“Undefined reference to” template class constructorWhy is 'int i = i;' legal?Turbo C++ and Code blocksFunction ambiguous in multiple inheritanceHow do I read from an input file after passing the ifstream object to a function?Passing Array of objects to same class C++a function-definition is not allowed here: void encryption(ifstream encrypt_file, ofstream keys_out, ofstream cipher_out) {






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















Why the compiler throw me error:invalid use of 'Student::Student'|



this is content file(ListOfStudent):1234 46567
this is my code:



class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()


vector<Student>ListOfStudent;

ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);



return 0;


Student::Student(string ML,string MSV)

this->ML=ML;
this->MSV=MSV;











share|improve this question






















  • Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

    – R Sahu
    Mar 24 at 7:29











  • @RSahu In what way is the question not an MCVE?

    – john
    Mar 24 at 7:38











  • You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

    – R Sahu
    Mar 24 at 7:42












  • You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45


















-1















Why the compiler throw me error:invalid use of 'Student::Student'|



this is content file(ListOfStudent):1234 46567
this is my code:



class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()


vector<Student>ListOfStudent;

ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);



return 0;


Student::Student(string ML,string MSV)

this->ML=ML;
this->MSV=MSV;











share|improve this question






















  • Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

    – R Sahu
    Mar 24 at 7:29











  • @RSahu In what way is the question not an MCVE?

    – john
    Mar 24 at 7:38











  • You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

    – R Sahu
    Mar 24 at 7:42












  • You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45














-1












-1








-1








Why the compiler throw me error:invalid use of 'Student::Student'|



this is content file(ListOfStudent):1234 46567
this is my code:



class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()


vector<Student>ListOfStudent;

ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);



return 0;


Student::Student(string ML,string MSV)

this->ML=ML;
this->MSV=MSV;











share|improve this question














Why the compiler throw me error:invalid use of 'Student::Student'|



this is content file(ListOfStudent):1234 46567
this is my code:



class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()


vector<Student>ListOfStudent;

ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);



return 0;


Student::Student(string ML,string MSV)

this->ML=ML;
this->MSV=MSV;








c++ codeblocks






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 7:23









KanKan

295




295












  • Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

    – R Sahu
    Mar 24 at 7:29











  • @RSahu In what way is the question not an MCVE?

    – john
    Mar 24 at 7:38











  • You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

    – R Sahu
    Mar 24 at 7:42












  • You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45


















  • Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

    – R Sahu
    Mar 24 at 7:29











  • @RSahu In what way is the question not an MCVE?

    – john
    Mar 24 at 7:38











  • You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

    – R Sahu
    Mar 24 at 7:42












  • You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45

















Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

– R Sahu
Mar 24 at 7:29





Please convert your code to a minimal reproducible example and post the complete error message from the compiler.

– R Sahu
Mar 24 at 7:29













@RSahu In what way is the question not an MCVE?

– john
Mar 24 at 7:38





@RSahu In what way is the question not an MCVE?

– john
Mar 24 at 7:38













You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

– R Sahu
Mar 24 at 7:42






You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.

– R Sahu
Mar 24 at 7:42














You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

– πάντα ῥεῖ
Mar 24 at 7:45






You cannot call the constructor via an instance. st.Student(ML,MSV); should be changed to st = Student(ML,MSV); or simpler Student st(ML,MSV);

– πάντα ῥεῖ
Mar 24 at 7:45













1 Answer
1






active

oldest

votes


















2














You can't call a constructor explicitely.
You should have written:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));



Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);



For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.






share|improve this answer

























  • The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

    – john
    Mar 24 at 7:36







  • 1





    The way Student is being constructed, emplace_back is the way to go I feel

    – Hemil
    Mar 24 at 8:26











  • yeah,my code was run,thank you so much for that

    – Kan
    Mar 25 at 4:39











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321579%2fi-would-like-to-obtain-information-from-a-text-file-and-assign-that-information%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can't call a constructor explicitely.
You should have written:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));



Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);



For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.






share|improve this answer

























  • The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

    – john
    Mar 24 at 7:36







  • 1





    The way Student is being constructed, emplace_back is the way to go I feel

    – Hemil
    Mar 24 at 8:26











  • yeah,my code was run,thank you so much for that

    – Kan
    Mar 25 at 4:39















2














You can't call a constructor explicitely.
You should have written:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));



Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);



For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.






share|improve this answer

























  • The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

    – john
    Mar 24 at 7:36







  • 1





    The way Student is being constructed, emplace_back is the way to go I feel

    – Hemil
    Mar 24 at 8:26











  • yeah,my code was run,thank you so much for that

    – Kan
    Mar 25 at 4:39













2












2








2







You can't call a constructor explicitely.
You should have written:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));



Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);



For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.






share|improve this answer















You can't call a constructor explicitely.
You should have written:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));



Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:



while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);



For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 10:07

























answered Mar 24 at 7:30









xryl669xryl669

1,7131329




1,7131329












  • The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

    – john
    Mar 24 at 7:36







  • 1





    The way Student is being constructed, emplace_back is the way to go I feel

    – Hemil
    Mar 24 at 8:26











  • yeah,my code was run,thank you so much for that

    – Kan
    Mar 25 at 4:39

















  • The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

    – john
    Mar 24 at 7:36







  • 1





    The way Student is being constructed, emplace_back is the way to go I feel

    – Hemil
    Mar 24 at 8:26











  • yeah,my code was run,thank you so much for that

    – Kan
    Mar 25 at 4:39
















The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

– john
Mar 24 at 7:36






The code is good but Student(ML,MSV) is an explicit constructor call isn't it?

– john
Mar 24 at 7:36





1




1





The way Student is being constructed, emplace_back is the way to go I feel

– Hemil
Mar 24 at 8:26





The way Student is being constructed, emplace_back is the way to go I feel

– Hemil
Mar 24 at 8:26













yeah,my code was run,thank you so much for that

– Kan
Mar 25 at 4:39





yeah,my code was run,thank you so much for that

– Kan
Mar 25 at 4:39



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321579%2fi-would-like-to-obtain-information-from-a-text-file-and-assign-that-information%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?