VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: [1] ]
Subject: Forritunarverkefni 2


Author:
Ymir
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 00:00:33 03/17/04 Wed

Mig langaši aš benda fólki į aš ķ staš žess eyša pśšri ķ aš bśa til ofsafenginn kóša til aš ašskilja orš (sbr. C ašferšir į borš viš strtok(), eša strchr() įsamt isspace()) er til afar einföld leiš til aš lesa inn strengi meš string klasanum ķ C++:

string s;
cin >> s;

mun lesa inn nęsta orš śr in-straumnum ķ s. Ef t.d. inntak er "Orš bla halló!" ķ eftirfarandi forritsbśt:

string s;
cin >> s; cout << "'" << s << "', ";
cin >> s; cout << "'" << s << "', ";
cin >> s; cout << "'" << s << "'.";

mun prentast śt 'Orš', 'bla', 'halló!'. Aš sjįlfsögšu mį nota ašra strauma ķ žessum tilgangi, t.a.m. vęri hentugt aš nota:

string s;
ifstream inp("bok.txt");
while (inp >> s)
{
cout << "Las oršiš '" << s << "'!\n";
}

sem mun hętta žegar öll orš śr skrįnni 'bok.txt' hafa veriš lesin.

Auk žess hafa borist spurningar um hvernig bera megi saman tvo strengi til aš raša žeim ķ röš. String klasinn bżšur einfaldlega upp į ašgerširnar '<', '>', og '==' fyrir samanburš. Dęmi:

string s1 = "Lambakaka", s2 = "Lambabaka";
if (s1 > s2) cout << "Whee!" << endl;

mun skila "Whee!" žar sem fyrri strengurinn er aftar en hinn seinni ķ stafrófinu m.t.t. ASCI-gilda.

Vona aš žetta nżtist einhverjum!

Kvešja,
Żmir

[ Next Thread | Previous Thread | Next Message | Previous Message ]


[ Contact Forum Admin ]


Forum timezone: GMT+0
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.