|
change to
printf("\nWhat is %d", *r1); (I already changed this)I figured that out.
kbury wrote:
r1 = 2 + rand() % 11;
change to
*r1 = 2 + rand() % 11; (This defineately fixed this.
The above steps, however just fix compiler errors...I don't know if the semantic will be correct.
switch (c)
{ (states that this is illegal type pointer to int in switch expression.)
case '1':
printf("+");
CorAns = r1 + r2; (operands of + have illegal of 'pointer to int' and 'pointer to int')
break;
|
|
|
|
|
kbury wrote: CorAns = r1 + r2;
change to
CorAns = *r1 + *r2;
The real solution, however, would be reading the f*#?n' book.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I do not believe that has been in any of the chapters that we have read so far, but I will look again at the latest chapter because each assignment is associated with that chapter.
|
|
|
|
|
|
I guess you're able to guess now.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am developing an application with three splitter panes, leftpane,right pane and bottom pane.
leftpane consists of a tree control, by clicking on the tree item, correspoding Dialog displayes in the right pane. For one tree item, by selecting it , i need to display another application by running winExec(), in right pane. I am facing problem at fitting this result application in the rightpane..I have tried with variuos Show window parameter for Winexec() call, but i failed.
thanks,
hema.
|
|
|
|
|
WinExec() spawns a new process.
If you want to show that in another application you need to create a relationship between the two applications.
You can do that using SetParent[^] and then use MoveWindow[^] to place it correctly in the right pane.
|
|
|
|
|
thanks for the reply..I will try it today..thanks a lot.
hema.
|
|
|
|
|
Hello people,
I am trying to make an application with in- and output. Input by textboxes and output by writing it to a file.
I succeeded to get text from a TextBox^ and put it in a RichTextBox^. No problem.
I succeeded to use fstream to 'print' data (string) to a file.
Now I want to combine these by using a vector<string>.
The problem I am facing is that if I do: fout << textBox->Text; that I get the following error:
1< d:\stageappvc\terminalapp\terminalapp\Form1.h(185) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
1< C:\Program Files\Microsoft Visual Studio 9.0\VC\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)
If I want to write the
textBox->Text to my vector. I get the following error:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(194) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
I tried to find out what this String^ actually is - but I could not find an accurate answer. I also tried:
textBox->Text.toString() which failed too.
Is anyone able to help me with this? I tried to find examples of how to put TextBox data in a string, but I couldn't find anything useful...
Kind regards,
Mikki Weesenaar
|
|
|
|
|
Don't use "System::String" instead use "std::string"
|
|
|
|
|
I have:
std::vector<string> textCode;
private: System::Windows::Forms::RichTextBox^ textBox;
private: System::Windows::Forms::TextBox^ invoerVeld;
textBox->Text += invoerVeld->Text + "\r\n"; < works fine
textCode.push_back(textBox->Text); < no-go
textCode.push_back(invoerVeld->Text);
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(194) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(195) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
So I think I cannot just use string in stead of String. Its a native thing of the TextBox and RichTextBox. I guess... Or if Im wrong, correct me 
|
|
|
|
|
I got this from MSDN -
String^ c = gcnew String("Change Me");
std::string str1 = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
std::wstring str2 = (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
|
|
|
|
|
I dont see the relation between the first line and the other two.
And I need it otherwise.
I have a String^ (coming from textBox->Text) and I want to store this in a string (which I have in a vector).
|
|
|
|
|
The first line creates a String^. I believe you already have that in textBox->Text.
The second line converts that to a string.
The third line converts that to a wstring.
What else do you not see?
|
|
|
|
|
I guess I need the second then.
Currently I have
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
But it gives me the following errors:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not found
So I tried to #include <marshal>, but that didn't work either.
How can I use this function?
And by the way - thanks for your fast replies 
|
|
|
|
|
Typo
It should be Marshal .
You got it wrong there.
Look at my posting.
|
|
|
|
|
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(7) : fatal error C1083: Cannot open include file: 'Marshal': No such file or directory
:p Yeh - I corrected it but copied the wrong stuff I saw...
But with A its still not working
I am using Visual C++ Express Edition. Downloaded the package yesterday :p
|
|
|
|
|
I suspect some mix-up in your code.
You do not have to include any file called Marshal .
And you can use this class only in managed applications.
|
|
|
|
|

#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
namespace TerminalApp {
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
std::vector<string> textCode;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ exitButton;
private: System::Windows::Forms::Button^ addText;
private: System::Windows::Forms::RichTextBox^ textBox;
private: System::Windows::Forms::Button^ saveButton;
private: System::Windows::Forms::TextBox^ invoerVeld;
private: System::Windows::Forms::Button^ voegTextButton;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->exitButton = (gcnew System::Windows::Forms::Button());
this->addText = (gcnew System::Windows::Forms::Button());
this->textBox = (gcnew System::Windows::Forms::RichTextBox());
this->saveButton = (gcnew System::Windows::Forms::Button());
this->invoerVeld = (gcnew System::Windows::Forms::TextBox());
this->voegTextButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->exitButton->Location = System::Drawing::Point(645, 269);
this->exitButton->Name = L"exitButton";
this->exitButton->Size = System::Drawing::Size(85, 35);
this->exitButton->TabIndex = 0;
this->exitButton->Text = L"Exit";
this->exitButton->UseVisualStyleBackColor = true;
this->exitButton->Click += gcnew System::EventHandler(this, &Form1::exitApp);
this->addText->Location = System::Drawing::Point(16, 24);
this->addText->Name = L"addText";
this->addText->Size = System::Drawing::Size(85, 35);
this->addText->TabIndex = 1;
this->addText->Text = L"AddText";
this->addText->UseVisualStyleBackColor = true;
this->addText->Click += gcnew System::EventHandler(this, &Form1::addText_Click);
this->textBox->Location = System::Drawing::Point(337, 24);
this->textBox->Name = L"textBox";
this->textBox->ReadOnly = true;
this->textBox->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::None;
this->textBox->Size = System::Drawing::Size(393, 239);
this->textBox->TabIndex = 2;
this->textBox->Text = L"";
this->saveButton->Location = System::Drawing::Point(554, 269);
this->saveButton->Name = L"saveButton";
this->saveButton->Size = System::Drawing::Size(85, 35);
this->saveButton->TabIndex = 3;
this->saveButton->Text = L"Save";
this->saveButton->UseVisualStyleBackColor = true;
this->saveButton->Click += gcnew System::EventHandler(this, &Form1::saveButton_Click);
this->invoerVeld->Location = System::Drawing::Point(16, 269);
this->invoerVeld->Name = L"invoerVeld";
this->invoerVeld->Size = System::Drawing::Size(130, 20);
this->invoerVeld->TabIndex = 4;
this->voegTextButton->Location = System::Drawing::Point(178, 269);
this->voegTextButton->Name = L"voegTextButton";
this->voegTextButton->Size = System::Drawing::Size(70, 34);
this->voegTextButton->TabIndex = 5;
this->voegTextButton->Text = L"VoegToe";
this->voegTextButton->UseVisualStyleBackColor = true;
this->voegTextButton->Click += gcnew System::EventHandler(this, &Form1::voegTextButton_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(742, 316);
this->Controls->Add(this->voegTextButton);
this->Controls->Add(this->invoerVeld);
this->Controls->Add(this->saveButton);
this->Controls->Add(this->textBox);
this->Controls->Add(this->addText);
this->Controls->Add(this->exitButton);
this->MaximizeBox = false;
this->MaximumSize = System::Drawing::Size(750, 350);
this->MinimumSize = System::Drawing::Size(750, 350);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Applicatie";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void exitApp(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void addText_Click(System::Object^ sender, System::EventArgs^ e) {
String^ tmp = textBox->Text;
textBox->Text = "\r\n" + tmp + "Blah";
}
private: System::Void saveButton_Click(System::Object^ sender, System::EventArgs^ e) {
fstream fout("c:/ostream.txt", std::ios_base::app);
textCode.push_back("1");
textCode.push_back("2");
textCode.push_back("3");
textCode.push_back("4");
textCode.push_back("5");
fout.close();
}
private: System::Void writeToTextbox(void) {
}
private: System::Void voegTextButton_Click(System::Object^ sender, System::EventArgs^ e) {
textBox->Text += invoerVeld->Text + "\r\n";
invoerVeld->Text = "";
invoerVeld->Focus();
writeToTextbox();
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
}
};
}
That's the code I have at the moment. Im trying to make a Forms Application - Im quite new to Forms Applications and only have made console apps before... :p
|
|
|
|
|
Try adding this line -
using namespace System::Runtime::InteropServices;
|
|
|
|
|
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not found
Is there any other known way to get text out such TextBox into a string? One made by Microsoft themselves? :p
|
|
|
|
|
You have typed in Marshel .
The correct spelling is Marshal .
Do you see the difference?
|
|
|
|
|
How strange - because I copied it directly from your post - since first of all I hate typing and secondly its always better to copy paste :p
But it is working now - let me test the output etc.
Thanks in advance <3
|
|
|
|
|
But I really think you should not be driving now.
|
|
|
|
|
No Im not driving lol.
It works!
*cheering the hell outta it*
Adding text to the TextBox and with a button its sending the data to my vector string which can be read and send to the output
Thank you very very much! I really needed this line!
<33 ![Rose | [Rose]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|