c++如何读取txt里的数据并判断后输出相应的值?

2025-01-02 17:33:03
推荐回答(1个)
回答1:

// aaa.cpp : Defines the entry point for the console application.

//


#include "stdafx.h"

#include


using namespace std;


int main(int argc, char* argv[])

{

char str[256];

FILE *fin;

fin = fopen("d:\\1.txt", "rt");

while (!feof(fin))

{

fscanf(fin, "%s", str);

if (strcmp(str, "00") == 0)

printf("a\n");

if (strcmp(str, "11") == 0)

printf("b\n");

}

fclose(fin);

}