c – 为struct属性分配不正确的值类型时的笑脸!

c – 为struct属性分配不正确的值类型时的笑脸!,第1张

概述我有点想知道我是否会失去理智,但我发誓,这段代码输出笑脸作为.name值!世界上发生了什么?到目前为止,它似乎仅在值为1时起作用,其他任何正确的方法都会产生错误. 我意识到代码存在缺陷 – >我不需要帮助. #include <iostream>#include <fstream>#include <regex>#include <string>#include <list>using 我有点想知道我是否会失去理智,但我发誓,这段代码输出笑脸作为.name值!世界上发生了什么?到目前为止,它似乎仅在值为1时起作用,其他任何正确的方法都会产生错误.

我意识到代码存在缺陷 – >我不需要帮助.

#include <iostream>#include <fstream>#include <regex>#include <string>#include <List>using namespace std;using namespace tr1;struct CollectedData{public:    string name;    float grade;};int main(){    string line;    List<CollectedData> AllData;    int count;    ifstream myfile("test_data.txt");    if (myfile.fail()) {cout << "Error opening file"; return 0;}    else    {        cout << "file opened... \n";        while( getline(myfile,line) ) {            CollectedData lineData;            lineData.name = 1;            lineData.grade = 2;            AllData.push_back(lineData);        }    }    cout << "\n\n file contents: \n";    List<CollectedData>::iterator Iterator;    for(Iterator = AllData.begin();             Iterator != AllData.end();            Iterator++)    {        cout << "\t" << (*Iterator).name << " - ";        cout << "\t" << (*Iterator).grade << "\n";    }    getchar();    return 1;}

总结

以上是内存溢出为你收集整理的c – 为struct属性分配不正确的值类型时的笑脸!全部内容,希望文章能够帮你解决c – 为struct属性分配不正确的值类型时的笑脸!所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1224401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存