|
Hey guys,
I am suppose to read in from a text file. M is the sex and 24 is the age.
The file I'm currently reading has the following code.
I am wondering what the ws is for. I see how fin >> sex is reading in the sex of the person and fin >> swimmer[actualSwimmers].age is reading in the age. What is the >> ws doing there???
Someone please help me out here
thanks in advance.
M 24
fin >> sex;
fin >> swimmers[actualSwimmers].age >> ws;
|
|
|
|
|
This is explictly skipping white space. I'm not sure of you need this in your code or not.
Steve
|
|
|
|
|
I'm trying to write a directX program and According to my text book I need to link to these two libraries: d3d9.lib and d3dx9.lib, I've gone to tools>options>Solutions and Projects>VC Directories and selected library paths from the drop down. I've than added C:\Program Files\Microsoft DirectX SDK (August 2006)\Lib\x86 as a new path. When I try and compile I'm only using one directX call (want to get this working before I go further or am able too ) and I get this output:
DirectXBase.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4
C:\Documents and Settings\Barryod\My Documents\Visual Studio 2005\Projects\DirectX1\Debug\DirectX1.exe : fatal error LNK1120: 1 unresolved externals
Now I've added the include path, I've added the direct lib path and #included the header files which the call I'm making is in. This is my first time using VC++ so I'm sure I'm just missing a blantant step somewhere . Any help is really appreciated as a silly error like this is frustating when you want to get stuck in.
|
|
|
|
|
Im not sure its helpful for you but see here[^]
|
|
|
|
|
You forgot to link to the libraries. Adding a library path doesn't mean that you will automatically link to all libraries that are in the path.
|
|
|
|
|
Ok thanks for the two replies, I've added this to my code:
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
And it now compiles. Do you always have to use this sort of command to link to a library? Is there not a way to do it through the IDE?
|
|
|
|
|
BarryOg wrote: Do you always have to use this sort of command to link to a library? Is there not a way to do it through the IDE?
You always have to link with the library. Now, there is another way of doing it. You can go in the project properties and there, in the link 'tab' you can specify which libraries to link to. The exact location of it depends of the IDE you are using. For example with VC2005, select the 'Linker' option -> 'Input' and add your libraries in 'Additional Dependencies'.
|
|
|
|
|
Ah ok, I wish they made that clearer. Well thanks for the help.
|
|
|
|
|
Hi
New to C++ but a bit stuck with this one.
I need to print a character eg: "x" multiple times on a console application.
I need to print "XXXXX" on the console in the place of an actual word as the user has to guess what the real word is. (Hangman based game)
i have used "example.length()" to obtain the amount of letters in the word but i need to transfer the "example.length()" to the relevant amount of "x's" to make up the word.
eg:
STARWARS must become XXXXXXXX on the console.
Can anyone help out with this one.
Thanks in advance.
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
for(int i=0;i<example.length();++i)
{
cout="" <<="" "x";
}
although,="" i="" think="" there's="" actually="" another="" way="" to="" do="" it,="" that's="" the="" most="" straightforward.
=""
<div="" class="ForumSig">Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The below code is not the simplest way of doing what you want. However, I assume you will be changing the X's as the user guesses the word. Thus, you can modify the PrintChar class to compare the guess with the answer, and print either an 'X' or the correct character.
#include <string>
#include <iostream>
#include <algorithm>
using std::wcout;
using std::endl;
using std::for_each;
using std::wstring;
class PrintChar {
public:
void operator() (const wchar_t& c)
{
wcout << L'X';
}
};
int _tmain(int argc, _TCHAR* argv[])
{
wstring answer = L"telephone";
for_each(answer.begin(), answer.end(), PrintChar());
wcout << endl;
return 0;
}
|
|
|
|
|
Thanks George
You have just answered my question and the next problem I was facing as well.
Will work on your code now and try to understand it before trying to implement it.
Much appreciated !!!
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
This might make more sense to you:
#include <string>
#include <iostream>
using std::wcout;
using std::endl;
using std::wstring;
typedef wstring::iterator wciter;
int _tmain(int argc, _TCHAR* argv[])
{
wstring answer = L"telephone";
wstring guess = L"pXlXXXXnX";
// Make sure both strings are the same size.
if (answer.size() == guess.size()) {
wciter a = answer.begin();
wciter g = guess.begin();
while (a != answer.end() && g != guess.end()) {
if (*a == *g) {
wcout << *a;
}
else {
wcout << L"X";
}
++a;
++g;
}
}
wcout << endl;
return 0;
}
|
|
|
|
|
Help me, I need to create a CFormView class with CToolBar, but when update my CFormView, the toolbar disappears. I'm use a MainFrame with CSplittstWnd, so the my program use many CFormView as controls. Inside de CFormView, I call the CtoolBar in OnInitialUpdate;
What is the error?
part of source code:
void CForm2::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
if (!m_toolBar2.Create( this ) ||
!m_toolBar2.LoadToolBar(IDR_TOOLBAR2))
{
TRACE0("Failed to create toolbar2\n");
return; // fail to create
}
m_toolBar2.SetBarStyle(CBRS_ALIGN_ANY | CBRS_TOOLTIPS | CBRS_FLYBY);
WINDOWPLACEMENT wndPlmnt2;
m_ctrlTB1Holder2.GetWindowPlacement(&wndPlmnt2);
m_toolBar2.GetToolBarCtrl().SetWindowPlacement(&wndPlmnt2);
m_toolTip2.Create(this, TTS_ALWAYSTIP);
CRect rect;
m_toolBar2.GetToolBarCtrl().GetItemRect(0, rect);
m_toolTip2.AddTool(&m_toolBar2, ID_TB2_ONE, rect, ID_TB2_ONE);
m_toolBar2.GetToolBarCtrl().GetItemRect(1, rect);
m_toolTip2.AddTool(&m_toolBar2, ID_TB2_TWO, rect, ID_TB2_TWO);
m_toolBar2.GetToolBarCtrl().SetToolTips(&m_toolTip2);
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
//////////////
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
(...)
if (!m_wndSplitter3.CreateView(0,0,RUNTIME_CLASS(CForm2),CSize(cr.Width()-100,cr.Height()-100),pContext))
{
TRACE(_T("failed to create view in third pane"));
return FALSE;
}
(...)
Later, I do another call the other "CForm1", but I return to "CForm2", your toolbar disappers, undertand?
|
|
|
|
|
Hi All,
I'm writing a program, part of which needs to read text from a .log file in UNICODE line by line, then convert it to ASCII and write it to an ASCII .log file line by line...
I've been battling with this issue for a week, and have yet to find a solution.
PS: I'm writing in C
Thanks a lot
Alex
|
|
|
|
|
What about W2A() ?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'll research this, thanks...
|
|
|
|
|
|
thanks for the extra info i'll do more researc and let you guys know my progress in this matter
|
|
|
|
|
|
|
Where can I post my Java questions?
Java kinda resembles C++, so can I post it here?
Thanks.
"C++ will solve any problem."
|
|
|
|
|
#hackC++ wrote: Java kinda resembles C++, so can I post it here?
You can, but you won't get very many responses ... and quite likely will get yelled at for doing so.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm trying to use a string as a parameter for CreateWindowEx and I'm getting compile errors. Firstly I was just casting it to a LPCWSTR as this was what the compiler error message was reported. This wasn't working as I was also casting from Ascii to UNICODE. _T() sorted that out. But I can't get _T() to work when I'm using a std::string. When I try and compile this code:
HWND hWnd = CreateWindow( _T("Barry's D3D BaseClass"), _T(windowName),
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,GetDesktopWindow(),
NULL, windowClass.hInstance, NULL );
gives the following error:
c:\documents and settings\barryod\my documents\visual studio 2005\projects\directx1\directx1\directxbase.cpp(38) : error C2065: 'LwindowName' : undeclared identifier
I'm not sure why its generating the LwindowName identifier, I've tried the .c_str function but that doesn't work either. Any help would be really appreciated.
|
|
|
|
|
If you are trying to write code (using the STL string) that will be compilible on both ANSI and UNICODE builds, you need to do a little work:
#ifdef UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif
There are a few other classes you may want to do the same thing for. Basically, what you will want is to use wstring when building with UNICODE, and string when building ANSI.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|