close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決 
Are you an avid runner? Or even just starting out?

Brooks designs high-performance men's and women's running shoes, apparel and accessories.
From our sponsors
C++讀檔字串解析
Oct 2nd 2013, 17:44

我試著不用 getline() 和 split().

1. TestFile.txt
A, HELLO
B, 1
7 0,1
4 5,6,7,8,9

2. code
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <strstream>
using namespace std;

void main()
{
FILE * f;
char buffer [100];
int num;

f = fopen ("TextFile1.txt" , "r");
if (f == NULL) perror ("Error opening file");
else
{
while ( ! feof (f) )
{
if ( fgets (buffer , 100 , f) == NULL ) break;
cout << "read " << buffer;

char *p = strtok(buffer, " ,"); // ',', space
while (p)
{
if ((*p >= 'A' && *p <= 'Z') ||
(*p >= 'a' && *p <= 'z'))
{ // A-Z, a-z
cout << p << endl; // do your job
}
else if (*p >= '0' && *p <= '9')
{
strstream ss(p, strlen(p));
ss >> num;
cout << num << endl;
}
p = strtok(0, " ,");
}
}
fclose (f);
}
system("pause");
}

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends:

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kkotgszvx368m 的頭像
    kkotgszvx368m

    【韓劇推薦】2016年8,韓劇看什麼呢?2016韓劇推薦好看的 , 2016韓劇推薦必看 , 2016韓劇 , 2016韓劇排行榜前十名 , 韓劇推薦 , 2016韓劇介紹 , 2016韓劇排行榜 , 2016韓劇列表 ,

    kkotgszvx368m 發表在 痞客邦 留言(0) 人氣()