string monthName; int totalDays; string firstWeekDay;
int i; int j;
cout << "interAction\nCalendar 1.1 (DA)\n\nIndtast sti til oprettelse af fil:"; getline(cin, filePath); cout << "Indtast kommende filnavn:"; getline(cin, fileName); cout << "Intast månedens navn:"; getline(cin, monthName); cout << "Indtast antal dage i måneden:"; getline(cin, totalDays); cout << "Indtast første ugedag i måneden::"; getline(cin, firstWeekDay); cout << "\nGenererer indhold..."; content = "<TABLE><TR><TD>Charlotte</TD><TD>Bent</TD><TD>Lars</TD><TD>Toke</TD></TR>"; for (i = 0; i < totalDays; i ++) { content = content + "<TR>"; for (j = 0; j < 4; j ++) { content = content + "<TD width=100>" + i + "</TD>"; } content = content + "</TR>"; } fullPath = filePath + fileName + ".html"; cout << "Opretter filen '" + fullPath + "'..."; ofstream f(fullPath.c_str()); //FILE *fp; //fp = fopen(sti.c_str(), "w"); cout << "\nSkriver '" + content + "'til '" + fullPath + "'..."; f << indhold; //fprintf(fp, indhold.c_str()); cout << "\nLukker '" + fullPath + "'..."; f.close(); //fclose(fp); cout << "\nSucces!\n\nTryk <ENTER> for at lukke dette vindue."; getchar(); }
Og compileren retunerer:
c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp: In function `int main()': c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:36: no matching function for call to `getline (_IO_istream_withassign &, int &)' c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:46: no match for `basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> > + int &' c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:56: `indhold' undeclared (first use this function) c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:56: (Each undeclared identifier is reported only once c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:56: for each function it appears in.)
string monthName; int totalDays; string firstWeekDay;
int i; int j;
cout << "interAction\nCalendar 1.1 (DA)\n\nIndtast sti til oprettelse af fil:"; getline(cin, filePath); cout << "Indtast kommende filnavn:"; getline(cin, fileName); cout << "Intast månedens navn:"; getline(cin, monthName); cout << "Indtast antal dage i måneden:"; getline(cin, totalDays); cout << "Indtast første ugedag i måneden::"; getline(cin, firstWeekDay); cout << "\nGenererer indhold..."; content = "<TABLE><TR><TD>Charlotte</TD><TD>Bent</TD><TD>Lars</TD><TD>Toke</TD></TR>"; for (i = 0; i < totalDays; i ++) { content = content + "<TR>"; for (j = 0; j < 4; j ++) { content = content + "<TD width=100>" + i + "</TD>"; } content = content + "</TR>"; } fullPath = filePath + fileName + ".html"; cout << "Opretter filen '" + fullPath + "'..."; ofstream f(fullPath.c_str()); //FILE *fp; //fp = fopen(sti.c_str(), "w"); cout << "\nSkriver '" + content + "'til '" + fullPath + "'..."; f << content; //fprintf(fp, indhold.c_str()); cout << "\nLukker '" + fullPath + "'..."; f.close(); //fclose(fp); cout << "\nSucces!\n\nTryk <ENTER> for at lukke dette vindue."; getchar(); }
Retunerer:
c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp: In function `int main()': c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:36: no matching function for call to `getline (_IO_istream_withassign &, int &)' c:\docume~1\admini~1\mydocu~1\c__~1\projek~2\main.cpp:46: no match for `basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> > + int &'
Jeg vil bare gerne vide, hvordan jeg får udskreet indholdet af en variabel (her 'i') til en fil. Ud for hver række (der består af fire felter vertikalt) skal datoen (som 'i' indikerer) stå. Så hvordan for jeg sat indholdet af 'i' ind?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.