Компилиране в C++ Visual Studio 6.0

3 отговора 168 прегледа
#1

Компилиране в C++ Visual Studio 6.0

Здравейте програмисти и сори за тъпия въпрос, ама няма как .....

Във C++ Visual Studio се компилира по стъпки с F11 (Step Into). Само, че когато стигне до един такъв фрагмент от програмата:

........
........
int k ;
while ( cin>>k ) {
i_st.push (k) ;
}
.........
.........

компилирането спира и чака явно да се въведе това “k”…. Добре де ама как се въвежда в по време на компилирането?



Отговор
в отговор на няkoй :) #2

Re: Компилиране в C++ Visual Studio 6.0

ami to wsyshnos ne se kompilira a se izpylniawa po stypki...
ami cin ti e potok swyrzan s standartnia whod, kato stdin
ot standartnata biblioteka na C
i whoda e ot konzolata, ili ot file ako ima prenasochwane
( wij pipes & redirection )
i si napiswash whoda w edin file :)) ako programata ti ne e konsolno prilojenie
bi triabwalo pri chetene ot cin da ti dawa eof...?? a ne da chaka...
chestno kazano az ne sym probwal towa :)
prenasochwaneto w VC++ sredata stawa taka:

From the Project menu, click Settings.
The Project Settings dialog box appears.
Select the Debug tab.
In the Program Arguments text box, specify one or more I/O redirection commands from the following table. You can combine I/O redirection commands in any order.
Click OK to accept the redirection and close the Project Settings dialog box.

Command Action :
<file Reads stdin from file (see Note below)
>file Sends stdout to file (see Note below)
>>file Appends stdout to file (see Note below)
2>file Sends stderr to file (see Note below)
2>>file Appends stderr to file
2>&1 Sends stderr (2) output to same location as stdout (1)
1>&2 Sends stdout (1) output to same location as stderr (2)

Note You can use the >, <, >>, and 2> commands for applications that read or write to stderr and stdout. In most (if not all) cases, this is specific to console applications.

Отговор
в отговор на няkoй :) #3

Re: Компилиране в C++ Visual Studio 6.0

Ако проекта който си започнал, е "Win32 Console Application", ще ти се покаже един черен джам и при "cin>>k" трябва да въведеш каквото ще въвеждаш в тоя джам.

Ако обаче си започнал "Win32 Application", cin и cout работят по-различно и не е добре да се ползуват. За да работят по-добре, трябва да използуваш пренасочване на входния поток от файл. cout поглъща данните и не ги праща никъде. cin е предназначен да въвежда данни от конзолата, а такава няма по подразбиране в такъв проект. Значи предварително трябва да си създадеш такава с функцията AllocConsole() и другата пасмина функции около нея.

Затова най-добре е такива експерименти като твоя да ги правиш с проект от типа "Win32 Console Application".

Отговор
в отговор на няkoй :) #4

oshte edin nachin

ako iskash sus malki promeni po sorsa da puskash consolno/windowed prilozhenie pod MSVC, ili da imash WinMain() i consola eto dobawi tozi kod w nachaloto na edin ot .cpp failovete si (da kazhem main.cpp ili main.c)


// Definiraj njakude tezi:
#define WIN32WINMAIN 0 /* 0:main(), 1:WinMain() */
#define WIN32CONSOLE 0 /* 0:no-console, 1:have-console */

....................

// Napravi si edin header fail (win32console.h da kazhem)
// I go includni wuw main.cpp (main.c) sled kato si includnat windows.h i drugite
// predi da go includnesh posochi tezi definiranite gore
// (WIN32WINMAIN, WIN32CONSOLE)
//
#ifndef __WIN32CONSOLE_INCLUDED
#define __WIN32CONSOLE_INCLUDED
#if defined(_MSC_VER) && defined(_WIN32)
#if WIN32WINMAIN
#if _UNICODE
#pragma comment(linker,"/ENTRY:wWinMainCRTStartup")
#else
#pragma comment(linker,"/ENTRY:WinMainCRTStartup")
#endif
#else
#if _UNICODE
#pragma comment(linker,"/ENTRY:wmainCRTStartup")
#else
#pragma comment(linker,"/ENTRY:mainCRTStartup")
#endif
#endif

#if WIN32CONSOLE
#pragma comment(linker,"/SUBSYSTEM:CONSOLE")
#else
#pragma comment(linker,"/SUBSYSTEM:WINDOWS")
#endif
#endif /* _MSC_VER, _WIN32 */
#endif /* __WIN32CONSOLE_INCLUDED__ */


tirulirutatuutuu
Отговор