Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決 
Find Unique T-shirts

Explore the most popular t-shirts on Cafepress. Discover great designs celebrating anything you can think of.
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
    全站熱搜
    創作者介紹
    創作者 jmuko104 的頭像
    jmuko104

    new htc one開箱,htc手機評價,htc手機比較,htc手機遊戲,htc手機維修,htc手機價位,htc手機推薦,htc手機鈴聲,中華電信htc手機,htc手機截圖,亞太htc手機,

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