如何从.txt文件中读取浮点数.根据每行开头的名称,我想读取不同数量的坐标.浮标由"空间"分隔.
例: triangle 1.2 -2.4 3.0
结果应该是:
float x = 1.2 / float y = -2.4 / float z = 3.0
该文件有更多的线条与不同的形状,可能会更复杂,但我想如果我知道如何做其中一个我可以自己做其他人.
我的代码到目前为止:
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
ifstream source; // build a read-Stream
source.open("text.txt", ios_base::in); // open data
if (!source) { // if it does not work
cerr << "Can't open Data!\n";
}
else { // if it worked
char c;
source.get(c); // get first character
if(c == 't'){ // if c is 't' …Run Code Online (Sandbox Code Playgroud) 我有以下课程
public class GameActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View gameView = new GameView(this);
setContentView(gameView);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在我的GameView类中添加一个Button.
public GameView(Context context) {
super(context);
// Code ...
}
Run Code Online (Sandbox Code Playgroud)
我在游戏过程中需要这个按钮,所以它应该是所有其他画布前面的'我正在画画.
我怎样才能做到这一点?
我将结果称为活动:
private static final int CODE_LOGIN = 0;
private static final int CODE_DETAILS = 1;
private void callDetailsActivity() {
Intent switchToDetailsActivity = new Intent(getApplicationContext(), Details.class);
switchToDetailsActivity.putExtra(TAG_ID, details.get(TAG_ID));
startActivityForResult(switchToDetailsActivity, CODE_DETAILS);
}
Run Code Online (Sandbox Code Playgroud)
现在在我的Details.class中,我打电话回到上一个活动:
@Override
public void onBackPressed() {
setResult(RESULT_OK);
super.onBackPressed();
}
Run Code Online (Sandbox Code Playgroud)
然后是我的 onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == CODE_LOGIN) {
// This is for my other Activity, where the "return" works
}
}
updateOffers(); …Run Code Online (Sandbox Code Playgroud)